OpenPop framework classes uses the property DefaultLogger.Log to obtain a logger where all logging information is sent to.
All loggers must implement the ILog interface:
/// <summary>
/// Defines a logger for managing system logging output
/// </summary>
public interface ILog
{
/// <summary>
/// Logs an error message to the logs
/// </summary>
/// <param name="message">This is the error message to log</param>
void LogError(string message);
/// <summary>
/// Logs a debug message to the logs
/// </summary>
/// <param name="message">This is the debug message to log</param>
void LogDebug(string message);
}
You can change what logger the DefaultLogger.Log property points to be calling DefaultLogger.SetLog(...) as done below:
/// <summary>
/// Example showing:
/// - How to change logging
/// - How to implement your own logger
/// </summary>
public static void ChangeLogging()
{
// All logging is sent trough logger defined at DefaultLogger.Log
// The logger can be changed by calling DefaultLogger.SetLog(someLogger)
// By default all logging is sent to the System.Diagnostics.Trace facilities.
// These are not very useful if you are not debugging
// Instead, lets send logging to a file:
DefaultLogger.SetLog(new FileLogger());
FileLogger.LogFile = new FileInfo("MyLoggingFile.log");
// It is also possible to implement your own logging:
DefaultLogger.SetLog(new MyOwnLogger());
}
Here is the custom implementation used:
class MyOwnLogger : ILog
{
public void LogError(string message)
{
Console.WriteLine("ERROR!!!: " + message);
}
public void LogDebug(string message)
{
// Dont want to log debug messages
}
}
If you just want to log to a file, you can use the FileLogger class.