|
XmlLogFile
A .NET logging library which inherits from DefaultTraceListener and provides a variety of advantages over traditional text file logging. Most importantly, it allows you to view your log messages in a browser and can save space in situations where identical messages are repeatedly written to the log. It is easier to read and more colorful than plain text log files and includes features for automatic rollover after the log gets to be a bigger than a user defined size (in KiloBytes).
You can create a log file like this (below). Don't forget to copy the included files "XmlLogFile.xslt" and "date.difference.template.xsl" into the log directory.
XmlLogFile log = new XmlLogFile("AppName", "c:\path\to\logs", "XmlLogFile.xslt", DebugLevel.Info);
log.MaxFileSize = 100; // size in KB
log.FlushCount = 20; // flush to disk after this many messages
Debug.Listeners.Add(log);
Debug.AutoFlush = true;
Debug.Write("A debug message");
log.Write("Log File created");
log.WriteLogEntry("Init", "Init message", DebugLevel.Summaries);
log.WriteLogEntryFormat("Error", "Error was {0}", DebugLevel.Errors, "error description");
log.WriteLogEntry(new Exception("This writes a message with DebugLevel.Exceptions"));
This log file will be flushed to disk after each 20 messages have been written or once the size of the log file exceeds 100KB. Also, because DebugLevel.Info was specified, only messages with DebugLevel of Info, Summaries, Warnings, Errors, and Exceptions will be included in the log file.
Log files are written to the log directory with a name like this:
AppName-2008_01_04-09.00.05-Info.xml
Also, if the log directory doesn't exist, XmlLogFile will create the directory.
Send feedback to twostepted@yahoo.com. Thanks for using XmlLogFile!
|