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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog { namespace SimpleLog {
@ -29,13 +27,13 @@ namespace SimpleLog {
public static readonly string Unix = "\n"; public static readonly string Unix = "\n";
} }
public class Logger : ILogger { public class DefaultLogger : ILogger {
/// <summary> /// <summary>
/// The singleton instance of this logger. All interactions /// The singleton instance of this logger. All interactions
/// with the logger should be done via this static property. /// with the logger should be done via this static property.
/// </summary> /// </summary>
public static readonly Logger Instance = new Logger(); public static readonly DefaultLogger Instance = new DefaultLogger();
/// <summary> /// <summary>
/// Gets or sets whether this logger is enabled or not /// Gets or sets whether this logger is enabled or not
/// </summary> /// </summary>
@ -47,7 +45,7 @@ namespace SimpleLog {
protected string dateFormat; protected string dateFormat;
protected string lineTerminator; protected string lineTerminator;
private Logger() { private DefaultLogger() {
this.LogHandlers = new List<ILogHandler>(); this.LogHandlers = new List<ILogHandler>();
this.logLevel = LogLevel.Warning; this.logLevel = LogLevel.Warning;
this.lineTerminator = SimpleLog.LineTerminator.Unix; this.lineTerminator = SimpleLog.LineTerminator.Unix;
@ -74,8 +72,11 @@ namespace SimpleLog {
allowedLevel = handler.LogLevel ?? this.LogLevel; allowedLevel = handler.LogLevel ?? this.LogLevel;
if (level <= allowedLevel) { if (level <= allowedLevel) {
messageHandler = handler.MessageHandler ?? this.MessageHandler; messageHandler = handler.MessageHandler ?? this.MessageHandler;
messageHandler.DateFormat = messageHandler.DateFormat ?? this.DateFormat;
convertedMessage = messageHandler.ConvertMessageToString(message); convertedMessage = messageHandler.ConvertMessageToString(message);
convertedMessage = messageHandler.ConstructLogMessage(handler, convertedMessage, level); convertedMessage = messageHandler.ConstructLogMessage(handler, convertedMessage, level);
success = (success && handler.Log(convertedMessage, allowedLevel)); success = (success && handler.Log(convertedMessage, allowedLevel));
} }
} }

View File

@ -1,9 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog { 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 { public class DefaultMessageHandler : IMessageHandler, IMessageFormatter {
protected string dateFormat; protected string dateFormat;
@ -13,7 +16,7 @@ namespace SimpleLog {
public DefaultMessageHandler() { public DefaultMessageHandler() {
this.dateFormat = null; this.dateFormat = null;
this.lineTerminator = null; this.lineTerminator = SimpleLog.LineTerminator.Unix;
this.context = ""; this.context = "";
this.delimiter = "\t"; this.delimiter = "\t";
} }
@ -28,7 +31,7 @@ namespace SimpleLog {
} }
messageData.Add(message); messageData.Add(message);
return string.Join(this.Delimiter, messageData.ToArray()); return string.Join(this.Delimiter, messageData.ToArray()) + this.LineTerminator;
} }
/// <summary> /// <summary>
@ -43,7 +46,7 @@ namespace SimpleLog {
string msg = null; string msg = null;
if (message is Exception) { if (message is Exception) {
Exception e = (Exception)message; Exception e = (Exception)message;
msg = e.Message + "\n" + e.StackTrace; msg = e.Message + this.LineTerminator + e.StackTrace;
} }
else { else {
msg = message.ToString(); msg = message.ToString();
@ -64,6 +67,9 @@ namespace SimpleLog {
} }
#endregion #endregion
/// <summary>
/// Gets or sets the delimiter used to separate log message data
/// </summary>
public string Delimiter { public string Delimiter {
get { get {
return this.delimiter; return this.delimiter;

View File

@ -1,9 +1,4 @@
using System; namespace SimpleLog {
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog {
public interface ILogHandler { public interface ILogHandler {
bool Log(object message, LogLevel level); bool Log(object message, LogLevel level);

View File

@ -1,9 +1,4 @@
using System; namespace SimpleLog {
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleLog {
public interface ILogger : IMessageFormatter { public interface ILogger : IMessageFormatter {
bool Log(object message, LogLevel level); bool Log(object message, LogLevel level);

View File

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

View File

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