Click here to Skip to main content
15,892,480 members
Articles / Programming Languages / C#
Article

Yet another Logger class

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
18 Aug 2002 62.6K   1.2K   24   4
The Logger class helps .NET developer create application logs in an easy way.
Image 1
Image 2

Introduction

This is a simple Log component that will help you to create Logs for your application. It is very simple and easy to use.

Code

The public static string GetNewLogFilename() creates a log filrname if DD-MM-YYYY.LOG format. You also have a LogType enum to specify the log entry types

C#
public enum LogType
{	 
	Info = 1,
	Warning = 2,
	Error = 3
}

How use use

C#
....
// GetNewLogFilename() is static member and dosn't need to be
// instantiated. Returns like 19-08-2002.log
string strMyLogFile = Logger.GetNewLogFilename()   
                                                   
Logger objLog = new Logger( strMyLogFile );
....
objLog.WriteLine(LogType.Info,"Application started.");
....
objLog.WriteLine(LogType.Warning,
                 "Application is going to fail here... be alert...");
....
objLog.WriteLine(LogType.Error,"The Application has died just now :(");
....
objLog.WriteLine(LogType.Info,"Terminating Application");

Have fun C#ing.

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
Netherlands Netherlands
Gevik Babakhani is a software architect currently residing in The Netherlands. He started programming as hobby from the age of 12. His professional career began in 1997. Since then he works fulltime as a software architect. Currently he dedicates time and effort in Microsoft.NET.
This is a Organisation (No members)


Comments and Discussions

 
GeneralDateTime format is off Pin
Mark F Garrison10-Mar-03 7:39
Mark F Garrison10-Mar-03 7:39 
Generallog4net, a better solution Pin
Roelof Blom27-Aug-02 4:45
Roelof Blom27-Aug-02 4:45 
GeneralRe: log4net, a better solution Pin
Anonymous27-Aug-02 10:55
Anonymous27-Aug-02 10:55 
GeneralRe: log4net, a better solution Pin
Stoney Tian17-Nov-02 23:00
Stoney Tian17-Nov-02 23:00 
i like this sample

My Homepage : http://accesine.go.163.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.