Click here to Skip to main content
15,896,269 members
Articles / Web Development / ASP.NET

Create Simple Error Log Files using ASP.NET and C#

Rate me:
Please Sign up or sign in to vote.
3.56/5 (44 votes)
27 May 20022 min read 778.6K   14.2K   100  
An article on generating text based error log files
using System;
using System.IO;
using System.Text;

namespace CreateLogFiles
{
	//<Summary>
	// This class used to created log files
	// Created by ali ahmad h - 2002
	//</Summary>

	public class CreateLogFiles
	{
		private string sLogFormat;
		private string sErrorTime;

		public CreateLogFiles()
		{
			//sLogFormat used to create log files format :
			// dd/mm/yyyy hh:mm:ss AM/PM ==> Log Message
			sLogFormat = DateTime.Now.ToShortDateString().ToString()+" "+DateTime.Now.ToLongTimeString().ToString()+" ==> ";
			
			//this variable used to create log filename format "
			//for example filename : ErrorLogYYYYMMDD
			string sYear	= DateTime.Now.Year.ToString();
			string sMonth	= DateTime.Now.Month.ToString();
			string sDay	= DateTime.Now.Day.ToString();
			sErrorTime = sYear+sMonth+sDay;
		}

		public void ErrorLog(string sPathName, string sErrMsg)
		{
			StreamWriter sw = new StreamWriter(sPathName+sErrorTime,true);
			sw.WriteLine(sLogFormat + sErrMsg);
			sw.Flush();
			sw.Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer AliAhmadH
Indonesia Indonesia
Was born at Subang - West Java, Indonesia. Like all IT related information include programming and networking. Can be emailed at ali(at)aliahmadh.com

Comments and Discussions