diff --git a/SimpleLog/Logger.cs b/SimpleLog/DefaultLogger.cs similarity index 91% rename from SimpleLog/Logger.cs rename to SimpleLog/DefaultLogger.cs index 18c8d34..9341599 100644 --- a/SimpleLog/Logger.cs +++ b/SimpleLog/DefaultLogger.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace SimpleLog { @@ -29,13 +27,13 @@ namespace SimpleLog { public static readonly string Unix = "\n"; } - public class Logger : ILogger { + public class DefaultLogger : ILogger { /// /// The singleton instance of this logger. All interactions /// with the logger should be done via this static property. /// - public static readonly Logger Instance = new Logger(); + public static readonly DefaultLogger Instance = new DefaultLogger(); /// /// Gets or sets whether this logger is enabled or not /// @@ -47,7 +45,7 @@ namespace SimpleLog { protected string dateFormat; protected string lineTerminator; - private Logger() { + private DefaultLogger() { this.LogHandlers = new List(); this.logLevel = LogLevel.Warning; this.lineTerminator = SimpleLog.LineTerminator.Unix; @@ -74,8 +72,11 @@ namespace SimpleLog { allowedLevel = handler.LogLevel ?? this.LogLevel; if (level <= allowedLevel) { messageHandler = handler.MessageHandler ?? this.MessageHandler; + messageHandler.DateFormat = messageHandler.DateFormat ?? this.DateFormat; + convertedMessage = messageHandler.ConvertMessageToString(message); convertedMessage = messageHandler.ConstructLogMessage(handler, convertedMessage, level); + success = (success && handler.Log(convertedMessage, allowedLevel)); } } diff --git a/SimpleLog/DefaultMessageHandler.cs b/SimpleLog/DefaultMessageHandler.cs index 3d33df2..2d07e05 100644 --- a/SimpleLog/DefaultMessageHandler.cs +++ b/SimpleLog/DefaultMessageHandler.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace SimpleLog { + /// + /// Default message handler. This class can be extended if slight + /// modification are needed, or it can serve as an example of how + /// to create a message handler. + /// public class DefaultMessageHandler : IMessageHandler, IMessageFormatter { protected string dateFormat; @@ -13,7 +16,7 @@ namespace SimpleLog { public DefaultMessageHandler() { this.dateFormat = null; - this.lineTerminator = null; + this.lineTerminator = SimpleLog.LineTerminator.Unix; this.context = ""; this.delimiter = "\t"; } @@ -28,7 +31,7 @@ namespace SimpleLog { } messageData.Add(message); - return string.Join(this.Delimiter, messageData.ToArray()); + return string.Join(this.Delimiter, messageData.ToArray()) + this.LineTerminator; } /// @@ -43,7 +46,7 @@ namespace SimpleLog { string msg = null; if (message is Exception) { Exception e = (Exception)message; - msg = e.Message + "\n" + e.StackTrace; + msg = e.Message + this.LineTerminator + e.StackTrace; } else { msg = message.ToString(); @@ -64,6 +67,9 @@ namespace SimpleLog { } #endregion + /// + /// Gets or sets the delimiter used to separate log message data + /// public string Delimiter { get { return this.delimiter; diff --git a/SimpleLog/ILogHandler.cs b/SimpleLog/ILogHandler.cs index 77ddaef..38da9e4 100644 --- a/SimpleLog/ILogHandler.cs +++ b/SimpleLog/ILogHandler.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SimpleLog { +namespace SimpleLog { public interface ILogHandler { bool Log(object message, LogLevel level); diff --git a/SimpleLog/ILogger.cs b/SimpleLog/ILogger.cs index 512d41f..2e48874 100644 --- a/SimpleLog/ILogger.cs +++ b/SimpleLog/ILogger.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SimpleLog { +namespace SimpleLog { public interface ILogger : IMessageFormatter { bool Log(object message, LogLevel level); diff --git a/SimpleLog/SimpleLog.csproj b/SimpleLog/SimpleLog.csproj index e6983b1..6c18a3d 100644 --- a/SimpleLog/SimpleLog.csproj +++ b/SimpleLog/SimpleLog.csproj @@ -45,12 +45,12 @@ + + - - diff --git a/SimpleLog/Util.cs b/SimpleLog/Util.cs index 34c865b..a8d14eb 100644 --- a/SimpleLog/Util.cs +++ b/SimpleLog/Util.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace SimpleLog { +namespace SimpleLog { public static class Util { ///