-
Notifications
You must be signed in to change notification settings - Fork 1
Logging :: Implementations :: DelegateLogger
mkloubert edited this page May 13, 2014
·
5 revisions
The DelegateLogger class uses functions or methods to log a message
public delegate void LogMessageHandler(ILogMessage msg);
The log message that was created for the DelegateLogger is send to each stored delegate, even if one invokation fails.
All delegates are called in the same thread.
class MyLogger {
public void DoLog(ILogMessage msg) {
//TODO
}
}
static class MyStaticLogger {
public static void LogTheMessage(ILogMessage msg) {
//TODO
}
}
var myLogger = new MyLogger();
var logger = new DelegateLogger();
// from instance method 'DoLog' of 'myLogger'
logger.Add(myLogger.DoLog);
// from class method 'LogTheMessage' of 'MyStaticLogger'
logger.Add(MyStaticLogger.LogTheMessage);
// log and send the log message to both added delegates
logger.Log("That should be logged in DEBUG mode only.",
LoggerFacadeCategories.Debug | LoggerFacadeCategories.Information);
The content is licensed under the GNU Free Documentation License v1.3.