Codebit ProgramLogger

This small C# Class can be used to create a simple Log-File in your .NET-program. All you have to do is providing the filename of your Log-File. Now you can easily write error- or info-messages or just plain text to this file with a short call. Timestamps are also supported.

Author

License

Usage & Example

see project "TestLogger"

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;// --> Use the namespace 'Codebit.ProgramLogger'usingCodebit.ProgramLogger;namespaceTestLogger{classProgram{staticvoidMain(string[]args){// Init new TXT-logLogFileLog=newLogFile("test.log",false,LogFile.LogType.TXT,LogFile.LogLevel.All);// Write some text to the logLog.LogRaw("ProgramLogger "+LogFile.VERSION+"(Build: "+LogFile.BUILD+") is loaded");Log.Log("START LOG",LogFile.LogLevel.Debug);Log.Log("Log-level is set to: "+Log.CurrentLogLevel,LogFile.LogLevel.Debug);Log.Log("Log-Type is "+Log.CurrentLogType,LogFile.LogLevel.Debug);Log.Log("LogText started",LogFile.LogLevel.Info);Log.Log("Write Log with default log-level");Log.DefaultLogLevel=LogFile.LogLevel.User1;Log.Log("Change default log-level to USER1");Log.Log("An fake-error occured ;)",LogFile.LogLevel.Error);Log.Log("CLOSE LOG",LogFile.LogLevel.Debug);/* ------------------------------------------------------------------------ */// Init new HTML-log, write only Debug and Error// (if you use this constructor, the log-file will be opened automatically)Log=newLogFile("test.log.html",false,LogFile.LogType.XHTML_Plain,LogFile.LogLevel.Debug|LogFile.LogLevel.Error,"TestLOG "+DateTime.Today.ToShortDateString());// Write some text to the logLog.LogRaw("<strong>ProgramLogger "+LogFile.VERSION+"(Build: "+LogFile.BUILD+") is loaded</strong><br/>");Log.Log("START LOG",LogFile.LogLevel.Debug);Log.Log("Log-level is set to: "+Log.CurrentLogLevel,LogFile.LogLevel.Debug);Log.Log("Log-Type is "+Log.CurrentLogType,LogFile.LogLevel.Debug);Log.Log("LogText started",LogFile.LogLevel.Info);//you shouldn't see this in the logLog.Log("An fake-error occured ;)",LogFile.LogLevel.Error);Log.Log("CLOSE LOG",LogFile.LogLevel.Debug);// write footer for a valid xhtml-fileLog.WriteFooter();}}}