From 09ebd0e0f6720e582ec42a202b3c0580ea7abcc7 Mon Sep 17 00:00:00 2001 From: tmont Date: Sun, 12 Apr 2009 08:34:22 +0000 Subject: [PATCH] added logging convenience methods --- SimpleLog/DefaultLogger.cs | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/SimpleLog/DefaultLogger.cs b/SimpleLog/DefaultLogger.cs index 7153b59..8e078be 100644 --- a/SimpleLog/DefaultLogger.cs +++ b/SimpleLog/DefaultLogger.cs @@ -31,6 +31,12 @@ namespace SimpleLog { } #region ILogger members + /// + /// Logs a message to all registered handlers + /// + /// The message to log + /// The log level of the message + /// TRUE if all handlers successfully logged the message, FALSE otherwise public bool Log(object message, LogLevel level) { bool success = true; @@ -55,10 +61,19 @@ namespace SimpleLog { return success; } + /// + /// Registers a log handler + /// public void RegisterLogHandler(ILogHandler handler) { this.LogHandlers.Add(handler); } + /// + /// Unregisters all log handlers that are instances or + /// derived instances of the specified class + /// + /// The fully qualified class name (e.g. SimpleLog.ILogHandler + /// The number of log handlers that were removed public int UnregisterLogHandlerType(string qualifiedClassName) { return this.LogHandlers.RemoveAll( delegate(ILogHandler handler) { @@ -68,6 +83,10 @@ namespace SimpleLog { ); } + /// + /// Unregisters all log handlers + /// + /// The number of log handlers that were removed public int UnregisterAllLogHandlers() { int count = this.LogHandlerCount; this.LogHandlers.RemoveRange(0, count); @@ -121,5 +140,40 @@ namespace SimpleLog { } } + /// + /// Logs a debug message + /// + public bool Debug(object message) { + return this.Log(message, LogLevel.Debug); + } + + /// + /// Logs an info message + /// + public bool Info(object message) { + return this.Log(message, LogLevel.Info); + } + + /// + /// Logs a warning message + /// + public bool Warning(object message) { + return this.Log(message, LogLevel.Warning); + } + + /// + /// Logs an error message + /// + public bool Error(object message) { + return this.Log(message, LogLevel.Error); + } + + /// + /// Logs a critical message + /// + public bool Critical(object message) { + return this.Log(message, LogLevel.Critical); + } + } }