renamed Logger to DefaultLogger, cleaned up usings

This commit is contained in:
tmont 2009-04-11 21:02:30 +00:00
parent ddeafdb9dd
commit 8da7843bc0
6 changed files with 22 additions and 30 deletions

View File

@ -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 {
/// <summary>
/// The singleton instance of this logger. All interactions
/// with the logger should be done via this static property.
/// </summary>
public static readonly Logger Instance = new Logger();
public static readonly DefaultLogger Instance = new DefaultLogger();
/// <summary>
/// Gets or sets whether this logger is enabled or not
/// </summary>
@ -47,7 +45,7 @@ namespace SimpleLog {
protected string dateFormat;
protected string lineTerminator;
private Logger() {
private DefaultLogger() {
this.LogHandlers = new List<ILogHandler>();
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));
}
}

View File

@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog {
/// <summary>
/// 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.
/// </summary>
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;
}
/// <summary>
@ -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
/// <summary>
/// Gets or sets the delimiter used to separate log message data
/// </summary>
public string Delimiter {
get {
return this.delimiter;

View File

@ -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);

View File

@ -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);

View File

@ -45,12 +45,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DefaultLogger.cs" />
<Compile Include="DefaultMessageHandler.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="IMessageFormatter.cs" />
<Compile Include="ILogHandler.cs" />
<Compile Include="IMessageHandler.cs" />
<Compile Include="Logger.cs" />
<Compile Include="MessageHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util.cs" />
</ItemGroup>

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog {
namespace SimpleLog {
public static class Util {
/// <summary>