diff --git a/SimpleLog.Tests/DefaultLoggerTest.cs b/SimpleLog.Tests/DefaultLoggerTest.cs
index 7d73ddd..5e0c3c1 100644
--- a/SimpleLog.Tests/DefaultLoggerTest.cs
+++ b/SimpleLog.Tests/DefaultLoggerTest.cs
@@ -29,7 +29,6 @@ namespace SimpleLog.Tests {
[Test]
public void TestRegisterAndUnregisterLogHandler() {
this.Handler.ExpectAndReturn("GetType", typeof(ILogHandler));
- //this.Handler.ExpectAndReturn("GetType", typeof(ILogHandler));
ILogHandler handler = (ILogHandler)this.Handler.MockInstance;
diff --git a/SimpleLog.Tests/Properties/AssemblyInfo.cs b/SimpleLog.Tests/Properties/AssemblyInfo.cs
deleted file mode 100644
index 90cf93c..0000000
--- a/SimpleLog.Tests/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("SimpleLog.Tests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Bridgepoint Education")]
-[assembly: AssemblyProduct("SimpleLog.Tests")]
-[assembly: AssemblyCopyright("Copyright © Bridgepoint Education 2009")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("36a0db9c-388f-41a7-a278-0aafa72986bb")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/SimpleLog.Tests/SimpleLog.Tests.csproj b/SimpleLog.Tests/SimpleLog.Tests.csproj
index 15f11fc..232dcf3 100644
--- a/SimpleLog.Tests/SimpleLog.Tests.csproj
+++ b/SimpleLog.Tests/SimpleLog.Tests.csproj
@@ -23,10 +23,10 @@
4
- pdbonly
+ none
true
bin\Release\
- TRACE
+
prompt
4
@@ -34,25 +34,12 @@
-
-
- 3.5
-
-
- 3.5
-
-
- 3.5
-
-
-
-
@@ -60,12 +47,9 @@
SimpleLog
+
+
+
-
+
\ No newline at end of file
diff --git a/Versioning.targets b/SimpleLog.targets
similarity index 79%
rename from Versioning.targets
rename to SimpleLog.targets
index 2494f6f..2df48db 100644
--- a/Versioning.targets
+++ b/SimpleLog.targets
@@ -3,12 +3,12 @@
- Tommy Montgomery
- Copyright (C) 2009 Tommy Montgomery
- 1
- 1
- 0
- 0
+ Tommy Montgomery
+ Copyright (C) 2009 Tommy Montgomery
+ 1
+ 2
+ 0
+ 0
Properties
ConfigureVersionNumber;
diff --git a/SimpleLog/SimpleLog.csproj b/SimpleLog/SimpleLog.csproj
index 5c99971..3b106dc 100644
--- a/SimpleLog/SimpleLog.csproj
+++ b/SimpleLog/SimpleLog.csproj
@@ -12,18 +12,19 @@
SimpleLog
v3.5
512
+ false
true
full
true
bin\Debug\
-
-
+ TRACE;DEBUG
prompt
4
+ true
None
@@ -33,21 +34,8 @@
prompt
4
+ bin\Release\SimpleLog.XML
-
-
-
- 3.5
-
-
- 3.5
-
-
- 3.5
-
-
-
-
@@ -65,5 +53,5 @@
-
+
\ No newline at end of file
diff --git a/SimpleLog/Src/DefaultLogger.cs b/SimpleLog/Src/DefaultLogger.cs
index dd1cf69..bb718ab 100644
--- a/SimpleLog/Src/DefaultLogger.cs
+++ b/SimpleLog/Src/DefaultLogger.cs
@@ -5,8 +5,7 @@ using SimpleLog.Framework;
namespace SimpleLog {
///
- /// Default logger class; illustrates how to use
- /// the SimpleLog framework.
+ /// Default, barebones logger. Gets the job done.
///
public class DefaultLogger : ILogger {
@@ -18,10 +17,25 @@ namespace SimpleLog {
#endregion
#region Protected members
+ ///
+ /// Collection of all registered log handlers
+ ///
protected List logHandlers;
+ ///
+ /// Message handler used by the logger
+ ///
protected IMessageHandler messageHandler;
+ ///
+ /// Global log level
+ ///
protected LogLevel logLevel;
+ ///
+ /// Global date format
+ ///
protected string dateFormat;
+ ///
+ /// Global line terminator
+ ///
protected string lineTerminator;
#endregion
@@ -29,7 +43,7 @@ namespace SimpleLog {
///
/// Creates a new DefaultLogger with the default settings
///
- public DefaultLogger() : this(LogLevel.Warning) {
+ public DefaultLogger() : this(LogLevel.Default) {
}
@@ -48,12 +62,12 @@ namespace SimpleLog {
/// The default log level
/// The line terminator
public DefaultLogger(IMessageHandler messageHandler, string dateFormat, LogLevel logLevel, string lineTerminator) {
- this.LogHandlers = new List();
- this.LogLevel = logLevel;
+ this.LogHandlers = new List();
+ this.LogLevel = logLevel;
this.LineTerminator = lineTerminator;
- this.Enabled = true;
+ this.Enabled = true;
this.MessageHandler = messageHandler;
- this.DateFormat = dateFormat;
+ this.DateFormat = dateFormat;
}
#endregion
@@ -72,8 +86,8 @@ namespace SimpleLog {
LogLevel allowedLevel;
IMessageHandler messageHandler;
foreach (ILogHandler handler in this.logHandlers) {
- allowedLevel = handler.LogLevel ?? (LogLevel)this.LogLevel;
- if (level >= allowedLevel) {
+ allowedLevel = (handler.LogLevel == SimpleLog.Framework.LogLevel.None) ? (LogLevel)this.LogLevel : handler.LogLevel;
+ if ((level & allowedLevel) > 0) {
messageHandler = handler.MessageHandler ?? this.MessageHandler;
messageHandler.DateFormat = messageHandler.DateFormat ?? this.DateFormat;
diff --git a/SimpleLog/Src/DefaultMessageHandler.cs b/SimpleLog/Src/DefaultMessageHandler.cs
index bdc12e7..b1dbb89 100644
--- a/SimpleLog/Src/DefaultMessageHandler.cs
+++ b/SimpleLog/Src/DefaultMessageHandler.cs
@@ -4,16 +4,28 @@ using SimpleLog.Framework;
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.
+ /// Default message handler
///
public class DefaultMessageHandler : IMessageHandler, IMessageFormatter {
#region Protected members
+ ///
+ /// Date format of this message handler
+ ///
protected string dateFormat;
+ ///
+ /// Line terminator used by this message handler
+ ///
protected string lineTerminator;
+ ///
+ /// Context string used by this message handler
+ ///
protected string context;
+ ///
+ /// Message component delimiter (e.g. in the message
+ /// "2009-04-17 [context] This is the message" a space
+ /// is the delimiter)
+ ///
protected string delimiter;
#endregion
diff --git a/SimpleLog/Src/Framework/ILogHandler.cs b/SimpleLog/Src/Framework/ILogHandler.cs
index c084e04..8f14cde 100644
--- a/SimpleLog/Src/Framework/ILogHandler.cs
+++ b/SimpleLog/Src/Framework/ILogHandler.cs
@@ -1,4 +1,10 @@
namespace SimpleLog.Framework {
+ ///
+ /// Interface for log handlers. Log handlers are injected
+ /// into ILoggers. They handle the physical act of actually
+ /// logging the message to the wherever that message should
+ /// go (e.g. file, console, output stream, nowhere, etc.).
+ ///
public interface ILogHandler {
///
@@ -9,14 +15,14 @@
///
/// Gets or sets the log level
///
- LogLevel? LogLevel { get; set; }
+ LogLevel LogLevel { get; set; }
///
/// Logs a message at the specified log level
///
/// The message to log
/// The log level of the message
- /// TRUE if all handler succesfully logged, or false if any of them failed
+ /// TRUE if all handlers succesfully logged, or false if any of them failed
bool Log(string message, LogLevel level);
///
diff --git a/SimpleLog/Src/Framework/ILogger.cs b/SimpleLog/Src/Framework/ILogger.cs
index 637a1fa..20314ab 100644
--- a/SimpleLog/Src/Framework/ILogger.cs
+++ b/SimpleLog/Src/Framework/ILogger.cs
@@ -1,4 +1,12 @@
namespace SimpleLog.Framework {
+ ///
+ /// ILoggers use ILogHandlers and IMessageHandlers
+ /// to log messages. They delegate the actual work
+ /// of logging to log handlers and message formatting
+ /// to the message handler. ILoggers are resonsible
+ /// for determining when a message should be logged (i.e.
+ /// handling the log level).
+ ///
public interface ILogger : IMessageFormatter {
///
@@ -7,12 +15,6 @@
/// The log handler to register
void RegisterLogHandler(ILogHandler handler);
- ///
- /// Unregisters the given log handler
- ///
- /// TRUE if successfully unregistered, FALSE if not
- //bool UnregisterLogHandler(ILogHandler handler);
-
///
/// Removes all log handlers that match the given assembly name
///
diff --git a/SimpleLog/Src/Framework/IMessageFormatter.cs b/SimpleLog/Src/Framework/IMessageFormatter.cs
index 6dc553d..b545223 100644
--- a/SimpleLog/Src/Framework/IMessageFormatter.cs
+++ b/SimpleLog/Src/Framework/IMessageFormatter.cs
@@ -1,4 +1,8 @@
namespace SimpleLog.Framework {
+ ///
+ /// Interface for formatting log messages into
+ /// whatever format they should be in.
+ ///
public interface IMessageFormatter {
///
diff --git a/SimpleLog/Src/Framework/IMessageHandler.cs b/SimpleLog/Src/Framework/IMessageHandler.cs
index 6162fe2..8bb0584 100644
--- a/SimpleLog/Src/Framework/IMessageHandler.cs
+++ b/SimpleLog/Src/Framework/IMessageHandler.cs
@@ -1,5 +1,10 @@
namespace SimpleLog.Framework {
+ ///
+ /// This interface handles message objects by converting
+ /// them to strings and formatting them (i.e. prepending
+ /// them with a timestamp).
+ ///
public interface IMessageHandler : IMessageFormatter {
///
diff --git a/SimpleLog/Src/Framework/Util.cs b/SimpleLog/Src/Framework/Util.cs
index aca8b8b..f1f5a8e 100644
--- a/SimpleLog/Src/Framework/Util.cs
+++ b/SimpleLog/Src/Framework/Util.cs
@@ -8,25 +8,45 @@ namespace SimpleLog.Framework {
[Flags]
public enum LogLevel {
///
- /// Debug message
+ /// No log level specified
///
- Debug = 1,
+ None = 0,
///
- /// Informational message
+ /// Debug level only
///
- Info = 2,
+ Debug = 1,
///
- /// Warning message
+ /// Informational level only
///
- Warning = 3,
+ Info = 2,
///
- /// Error message
+ /// Warning level only
///
- Error = 4,
+ Warning = 4,
///
- /// Critical death message
+ /// Error level only
///
- Critical = 5
+ Error = 8,
+ ///
+ /// Critical death level only
+ ///
+ Critical = 16,
+ ///
+ /// Preferred alias of Critical
+ ///
+ OhNoes = 16,
+ ///
+ /// Debug and Info only
+ ///
+ LowPriority = Debug | Info,
+ ///
+ /// Default log level: Warning, Error and Critical
+ ///
+ Default = Warning | Error | Critical,
+ ///
+ /// All messages are logged
+ ///
+ All = Debug | Info | Warning | Error | Critical
}
///
diff --git a/SimpleLog/Src/LogHandlers/ConsoleLogHandler.cs b/SimpleLog/Src/LogHandlers/ConsoleLogHandler.cs
index 33d924a..78183f2 100644
--- a/SimpleLog/Src/LogHandlers/ConsoleLogHandler.cs
+++ b/SimpleLog/Src/LogHandlers/ConsoleLogHandler.cs
@@ -8,23 +8,38 @@ namespace SimpleLog.LogHandlers {
///
public class ConsoleLogHandler : ILogHandler {
+ ///
+ /// Message handler used by this log handler
+ ///
protected IMessageHandler messageHandler;
- protected LogLevel? logLevel;
+ ///
+ /// Log level of this log handler
+ ///
+ protected LogLevel logLevel;
//stolen from log4net
- public const UInt32 STD_OUTPUT_HANDLE = unchecked((UInt32)(-11));
- public const UInt32 STD_ERROR_HANDLE = unchecked((UInt32)(-12));
+ ///
+ /// stdout handle
+ ///
+ public const uint STD_OUTPUT_HANDLE = unchecked((UInt32)(-11));
+ ///
+ /// stderr handle
+ ///
+ public const uint STD_ERROR_HANDLE = unchecked((UInt32)(-12));
///
/// Constructs a new ConsoleLogHandler with a default
/// message handler
///
public ConsoleLogHandler() {
- this.messageHandler = new DefaultMessageHandler();
- this.logLevel = null;
+ this.MessageHandler = new DefaultMessageHandler();
+ this.LogLevel = SimpleLog.Framework.LogLevel.None;
}
#region ILogHandler Members
+ ///
+ /// Gracefully shuts down this log handler
+ ///
public virtual void GracefulShutDown() {
//does nothing
}
@@ -32,7 +47,7 @@ namespace SimpleLog.LogHandlers {
///
/// Gets or sets the log level for this handler
///
- public LogLevel? LogLevel {
+ public LogLevel LogLevel {
get {
return this.logLevel;
}
diff --git a/SimpleLog/Src/LogHandlers/ConsoleWindowLogHandler.cs b/SimpleLog/Src/LogHandlers/ConsoleWindowLogHandler.cs
index 41278d1..ba81261 100644
--- a/SimpleLog/Src/LogHandlers/ConsoleWindowLogHandler.cs
+++ b/SimpleLog/Src/LogHandlers/ConsoleWindowLogHandler.cs
@@ -9,13 +9,37 @@ namespace SimpleLog.LogHandlers {
///
[Flags]
public enum ConsoleColor : int {
+ ///
+ /// The color blue
+ ///
Blue = 0x0001,
+ ///
+ /// The color green
+ ///
Green = 0x0002,
+ ///
+ /// The color red
+ ///
Red = 0x0004,
+ ///
+ /// The color white (Red, Green and Blue combined)
+ ///
White = Blue | Green | Red,
+ ///
+ /// The color yellow (Red and Green combined)
+ ///
Yellow = Red | Green,
+ ///
+ /// The color purple (Red and Blue combined)
+ ///
Purple = Red | Blue,
+ ///
+ /// The color cyan (Green and Blue combined)
+ ///
Cyan = Green | Blue,
+ ///
+ /// Brightens a color
+ ///
HighIntensity = 0x0008,
}
diff --git a/SimpleLog/Src/LogHandlers/FileLogHandler.cs b/SimpleLog/Src/LogHandlers/FileLogHandler.cs
index 547e5da..8ab6efa 100644
--- a/SimpleLog/Src/LogHandlers/FileLogHandler.cs
+++ b/SimpleLog/Src/LogHandlers/FileLogHandler.cs
@@ -3,13 +3,33 @@ using System.IO;
using SimpleLog.Framework;
namespace SimpleLog.LogHandlers {
+ ///
+ /// Log handler for filesystem-based logging
+ ///
public class FileLogHandler : ILogHandler {
+ ///
+ /// Message handler used by this log handler
+ ///
protected IMessageHandler messageHandler;
- protected LogLevel? logLevel;
+ ///
+ /// Log level of this log handler
+ ///
+ protected LogLevel logLevel;
+ ///
+ /// Directory in which to create the log files
+ ///
protected string logDirectory;
+ ///
+ /// The string that prepends each log file name (e.g.
+ /// in logger_20090417.log, "logger" is the filePrefix)
+ ///
protected string filePrefix;
+ ///
+ /// The file extension of each log file (e.g.
+ /// in logger_20090417.log, ".log" is the fileSuffix)
+ ///
protected string fileSuffix;
#region Constructors
@@ -30,10 +50,10 @@ namespace SimpleLog.LogHandlers {
/// The file suffix (e.g. ".log")
public FileLogHandler(string dir, string prefix, string suffix) {
this.messageHandler = new DefaultMessageHandler();
- this.logLevel = null;
- this.logDirectory = dir;
- this.filePrefix = prefix;
- this.fileSuffix = suffix;
+ this.LogLevel = SimpleLog.Framework.LogLevel.None;
+ this.LogDirectory = dir;
+ this.FilePrefix = prefix;
+ this.FileSuffix = suffix;
}
#endregion
@@ -48,7 +68,7 @@ namespace SimpleLog.LogHandlers {
///
/// Gets or sets the log level
///
- public LogLevel? LogLevel {
+ public LogLevel LogLevel {
get {
return this.logLevel;
}
@@ -94,7 +114,7 @@ namespace SimpleLog.LogHandlers {
///
protected virtual string BuildFileName() {
string fileName = this.logDirectory + Path.DirectorySeparatorChar + this.FilePrefix;
- fileName += "_" + string.Format("{0:yyyyMMdd}", DateTime.Now) + this.FileSuffix;
+ fileName += "_" + string.Format("{0:yyyyMMdd}", DateTime.Now) + this.FileSuffix;
return fileName;
}