blog
twitter
Termite Logging Framework for .NET termite VS Tool online logging
 
tweet tweet tweet tweet tweet

Formatting Log Entries

Simple Date/Time Formatting

Every logger has a formatter. Each formatter has a FormatString used for formatting its timestamp. You can customize the way the timestamp appears by doing something such as

/* this is the long format for both date and time */
logger.Formatter.FormatString = "F";

Advanced Formatting

The way a LogEntry looks in a log can be completely customized. By default every logger uses an instance of LogEntryStandardFormatter. However, you can create your own subclasses of the abstract class LogEntryFormatter. Simply override the AsString(LogEntry) method to provide a completely custom look in the log.

LogEntryFormatter myFormatter = new MyCustomLogEntryFormatter();
logger.Formatter = myFormatter;

Changing the default formatter

You can also change the default formatter for all your logger instances by doing something like:

Logger.DefaultFormatterClass = typeof( MyCustomLogEntryFormatter );

LogEntryFormatStringFormatter

This class will provide extremely flexible formatting.

You can create your own custom format string with various parameters, such as "{timestamp:G} - {application} - {machine} - {severity} - {category} - {message}"

Take a look here for more about format strings.