SimpleLog 1.2 branch reintegration
This commit is contained in:
parent
f44b12cf56
commit
7e28eeed30
@ -29,7 +29,6 @@ namespace SimpleLog.Tests {
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestRegisterAndUnregisterLogHandler() {
|
public void TestRegisterAndUnregisterLogHandler() {
|
||||||
this.Handler.ExpectAndReturn("GetType", typeof(ILogHandler));
|
this.Handler.ExpectAndReturn("GetType", typeof(ILogHandler));
|
||||||
//this.Handler.ExpectAndReturn("GetType", typeof(ILogHandler));
|
|
||||||
|
|
||||||
ILogHandler handler = (ILogHandler)this.Handler.MockInstance;
|
ILogHandler handler = (ILogHandler)this.Handler.MockInstance;
|
||||||
|
|
||||||
|
@ -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")]
|
|
@ -23,10 +23,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants></DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -34,25 +34,12 @@
|
|||||||
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||||
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||||
<Reference Include="nunit.mocks, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
<Reference Include="nunit.mocks, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Xml.Linq">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data.DataSetExtensions">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ConsoleLogHandlerTest.cs" />
|
<Compile Include="ConsoleLogHandlerTest.cs" />
|
||||||
<Compile Include="DefaultLoggerTest.cs" />
|
<Compile Include="DefaultLoggerTest.cs" />
|
||||||
<Compile Include="DefaultMessageHandlerTest.cs" />
|
<Compile Include="DefaultMessageHandlerTest.cs" />
|
||||||
<Compile Include="LoggerManagerTest.cs" />
|
<Compile Include="LoggerManagerTest.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SimpleLog\SimpleLog.csproj">
|
<ProjectReference Include="..\SimpleLog\SimpleLog.csproj">
|
||||||
@ -60,12 +47,9 @@
|
|||||||
<Name>SimpleLog</Name>
|
<Name>SimpleLog</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<Import Project="..\SimpleLog.targets" />
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
</Project>
|
@ -3,12 +3,12 @@
|
|||||||
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
|
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Producer Condition="$(Producer) == ''">Tommy Montgomery</Producer>
|
<Producer>Tommy Montgomery</Producer>
|
||||||
<Copyright Condition="$(Copyright) == ''">Copyright (C) 2009 Tommy Montgomery</Copyright>
|
<Copyright>Copyright (C) 2009 Tommy Montgomery</Copyright>
|
||||||
<MajorVersion Condition="$(MajorVersion) == ''">1</MajorVersion>
|
<MajorVersion>1</MajorVersion>
|
||||||
<MinorVersion Condition="$(MinorVersion) == ''">1</MinorVersion>
|
<MinorVersion>2</MinorVersion>
|
||||||
<BuildNumber Condition="$(BuildNumber) == ''">0</BuildNumber>
|
<BuildNumber>0</BuildNumber>
|
||||||
<RevisionNumber Condition="$(RevisionNumber) == ''">0</RevisionNumber>
|
<RevisionNumber>0</RevisionNumber>
|
||||||
<PropertiesDir>Properties</PropertiesDir>
|
<PropertiesDir>Properties</PropertiesDir>
|
||||||
<BuildDependsOn>
|
<BuildDependsOn>
|
||||||
ConfigureVersionNumber;
|
ConfigureVersionNumber;
|
@ -12,18 +12,19 @@
|
|||||||
<AssemblyName>SimpleLog</AssemblyName>
|
<AssemblyName>SimpleLog</AssemblyName>
|
||||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<SignAssembly>false</SignAssembly>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<DocumentationFile>
|
<DocumentationFile>
|
||||||
</DocumentationFile>
|
</DocumentationFile>
|
||||||
|
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>None</DebugType>
|
<DebugType>None</DebugType>
|
||||||
@ -33,21 +34,8 @@
|
|||||||
</DefineConstants>
|
</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DocumentationFile>bin\Release\SimpleLog.XML</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Xml.Linq">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data.DataSetExtensions">
|
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Src\DefaultLogger.cs" />
|
<Compile Include="Src\DefaultLogger.cs" />
|
||||||
<Compile Include="Src\DefaultMessageHandler.cs" />
|
<Compile Include="Src\DefaultMessageHandler.cs" />
|
||||||
@ -65,5 +53,5 @@
|
|||||||
<Folder Include="Properties\" />
|
<Folder Include="Properties\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="..\Versioning.targets" />
|
<Import Project="..\SimpleLog.targets" />
|
||||||
</Project>
|
</Project>
|
@ -5,8 +5,7 @@ using SimpleLog.Framework;
|
|||||||
namespace SimpleLog {
|
namespace SimpleLog {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default logger class; illustrates how to use
|
/// Default, barebones logger. Gets the job done.
|
||||||
/// the SimpleLog framework.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultLogger : ILogger {
|
public class DefaultLogger : ILogger {
|
||||||
|
|
||||||
@ -18,10 +17,25 @@ namespace SimpleLog {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Protected members
|
#region Protected members
|
||||||
|
/// <summary>
|
||||||
|
/// Collection of all registered log handlers
|
||||||
|
/// </summary>
|
||||||
protected List<ILogHandler> logHandlers;
|
protected List<ILogHandler> logHandlers;
|
||||||
|
/// <summary>
|
||||||
|
/// Message handler used by the logger
|
||||||
|
/// </summary>
|
||||||
protected IMessageHandler messageHandler;
|
protected IMessageHandler messageHandler;
|
||||||
|
/// <summary>
|
||||||
|
/// Global log level
|
||||||
|
/// </summary>
|
||||||
protected LogLevel logLevel;
|
protected LogLevel logLevel;
|
||||||
|
/// <summary>
|
||||||
|
/// Global date format
|
||||||
|
/// </summary>
|
||||||
protected string dateFormat;
|
protected string dateFormat;
|
||||||
|
/// <summary>
|
||||||
|
/// Global line terminator
|
||||||
|
/// </summary>
|
||||||
protected string lineTerminator;
|
protected string lineTerminator;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -29,7 +43,7 @@ namespace SimpleLog {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new DefaultLogger with the default settings
|
/// Creates a new DefaultLogger with the default settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DefaultLogger() : this(LogLevel.Warning) {
|
public DefaultLogger() : this(LogLevel.Default) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +62,12 @@ namespace SimpleLog {
|
|||||||
/// <param name="logLevel">The default log level</param>
|
/// <param name="logLevel">The default log level</param>
|
||||||
/// <param name="lineTerminator">The line terminator</param>
|
/// <param name="lineTerminator">The line terminator</param>
|
||||||
public DefaultLogger(IMessageHandler messageHandler, string dateFormat, LogLevel logLevel, string lineTerminator) {
|
public DefaultLogger(IMessageHandler messageHandler, string dateFormat, LogLevel logLevel, string lineTerminator) {
|
||||||
this.LogHandlers = new List<ILogHandler>();
|
this.LogHandlers = new List<ILogHandler>();
|
||||||
this.LogLevel = logLevel;
|
this.LogLevel = logLevel;
|
||||||
this.LineTerminator = lineTerminator;
|
this.LineTerminator = lineTerminator;
|
||||||
this.Enabled = true;
|
this.Enabled = true;
|
||||||
this.MessageHandler = messageHandler;
|
this.MessageHandler = messageHandler;
|
||||||
this.DateFormat = dateFormat;
|
this.DateFormat = dateFormat;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -72,8 +86,8 @@ namespace SimpleLog {
|
|||||||
LogLevel allowedLevel;
|
LogLevel allowedLevel;
|
||||||
IMessageHandler messageHandler;
|
IMessageHandler messageHandler;
|
||||||
foreach (ILogHandler handler in this.logHandlers) {
|
foreach (ILogHandler handler in this.logHandlers) {
|
||||||
allowedLevel = handler.LogLevel ?? (LogLevel)this.LogLevel;
|
allowedLevel = (handler.LogLevel == SimpleLog.Framework.LogLevel.None) ? (LogLevel)this.LogLevel : handler.LogLevel;
|
||||||
if (level >= allowedLevel) {
|
if ((level & allowedLevel) > 0) {
|
||||||
messageHandler = handler.MessageHandler ?? this.MessageHandler;
|
messageHandler = handler.MessageHandler ?? this.MessageHandler;
|
||||||
messageHandler.DateFormat = messageHandler.DateFormat ?? this.DateFormat;
|
messageHandler.DateFormat = messageHandler.DateFormat ?? this.DateFormat;
|
||||||
|
|
||||||
|
@ -4,16 +4,28 @@ using SimpleLog.Framework;
|
|||||||
|
|
||||||
namespace SimpleLog {
|
namespace SimpleLog {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default message handler. This class can be extended if slight
|
/// Default message handler
|
||||||
/// modification are needed, or it can serve as an example of how
|
|
||||||
/// to create a message handler.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultMessageHandler : IMessageHandler, IMessageFormatter {
|
public class DefaultMessageHandler : IMessageHandler, IMessageFormatter {
|
||||||
|
|
||||||
#region Protected members
|
#region Protected members
|
||||||
|
/// <summary>
|
||||||
|
/// Date format of this message handler
|
||||||
|
/// </summary>
|
||||||
protected string dateFormat;
|
protected string dateFormat;
|
||||||
|
/// <summary>
|
||||||
|
/// Line terminator used by this message handler
|
||||||
|
/// </summary>
|
||||||
protected string lineTerminator;
|
protected string lineTerminator;
|
||||||
|
/// <summary>
|
||||||
|
/// Context string used by this message handler
|
||||||
|
/// </summary>
|
||||||
protected string context;
|
protected string context;
|
||||||
|
/// <summary>
|
||||||
|
/// Message component delimiter (e.g. in the message
|
||||||
|
/// "2009-04-17 [context] This is the message" a space
|
||||||
|
/// is the delimiter)
|
||||||
|
/// </summary>
|
||||||
protected string delimiter;
|
protected string delimiter;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
namespace SimpleLog.Framework {
|
namespace SimpleLog.Framework {
|
||||||
|
/// <summary>
|
||||||
|
/// 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.).
|
||||||
|
/// </summary>
|
||||||
public interface ILogHandler {
|
public interface ILogHandler {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -9,14 +15,14 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the log level
|
/// Gets or sets the log level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
LogLevel? LogLevel { get; set; }
|
LogLevel LogLevel { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logs a message at the specified log level
|
/// Logs a message at the specified log level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to log</param>
|
/// <param name="message">The message to log</param>
|
||||||
/// <param name="level">The log level of the message</param>
|
/// <param name="level">The log level of the message</param>
|
||||||
/// <returns>TRUE if all handler succesfully logged, or false if any of them failed</returns>
|
/// <returns>TRUE if all handlers succesfully logged, or false if any of them failed</returns>
|
||||||
bool Log(string message, LogLevel level);
|
bool Log(string message, LogLevel level);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
namespace SimpleLog.Framework {
|
namespace SimpleLog.Framework {
|
||||||
|
/// <summary>
|
||||||
|
/// 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).
|
||||||
|
/// </summary>
|
||||||
public interface ILogger : IMessageFormatter {
|
public interface ILogger : IMessageFormatter {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -7,12 +15,6 @@
|
|||||||
/// <param name="handler">The log handler to register</param>
|
/// <param name="handler">The log handler to register</param>
|
||||||
void RegisterLogHandler(ILogHandler handler);
|
void RegisterLogHandler(ILogHandler handler);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unregisters the given log handler
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>TRUE if successfully unregistered, FALSE if not</returns>
|
|
||||||
//bool UnregisterLogHandler(ILogHandler handler);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes all log handlers that match the given assembly name
|
/// Removes all log handlers that match the given assembly name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
namespace SimpleLog.Framework {
|
namespace SimpleLog.Framework {
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for formatting log messages into
|
||||||
|
/// whatever format they should be in.
|
||||||
|
/// </summary>
|
||||||
public interface IMessageFormatter {
|
public interface IMessageFormatter {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
namespace SimpleLog.Framework {
|
namespace SimpleLog.Framework {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This interface handles message objects by converting
|
||||||
|
/// them to strings and formatting them (i.e. prepending
|
||||||
|
/// them with a timestamp).
|
||||||
|
/// </summary>
|
||||||
public interface IMessageHandler : IMessageFormatter {
|
public interface IMessageHandler : IMessageFormatter {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -8,25 +8,45 @@ namespace SimpleLog.Framework {
|
|||||||
[Flags]
|
[Flags]
|
||||||
public enum LogLevel {
|
public enum LogLevel {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Debug message
|
/// No log level specified
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Debug = 1,
|
None = 0,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Informational message
|
/// Debug level only
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Info = 2,
|
Debug = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Warning message
|
/// Informational level only
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Warning = 3,
|
Info = 2,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error message
|
/// Warning level only
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Error = 4,
|
Warning = 4,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Critical death message
|
/// Error level only
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Critical = 5
|
Error = 8,
|
||||||
|
/// <summary>
|
||||||
|
/// Critical death level only
|
||||||
|
/// </summary>
|
||||||
|
Critical = 16,
|
||||||
|
/// <summary>
|
||||||
|
/// Preferred alias of Critical
|
||||||
|
/// </summary>
|
||||||
|
OhNoes = 16,
|
||||||
|
/// <summary>
|
||||||
|
/// Debug and Info only
|
||||||
|
/// </summary>
|
||||||
|
LowPriority = Debug | Info,
|
||||||
|
/// <summary>
|
||||||
|
/// Default log level: Warning, Error and Critical
|
||||||
|
/// </summary>
|
||||||
|
Default = Warning | Error | Critical,
|
||||||
|
/// <summary>
|
||||||
|
/// All messages are logged
|
||||||
|
/// </summary>
|
||||||
|
All = Debug | Info | Warning | Error | Critical
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -8,23 +8,38 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ConsoleLogHandler : ILogHandler {
|
public class ConsoleLogHandler : ILogHandler {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message handler used by this log handler
|
||||||
|
/// </summary>
|
||||||
protected IMessageHandler messageHandler;
|
protected IMessageHandler messageHandler;
|
||||||
protected LogLevel? logLevel;
|
/// <summary>
|
||||||
|
/// Log level of this log handler
|
||||||
|
/// </summary>
|
||||||
|
protected LogLevel logLevel;
|
||||||
|
|
||||||
//stolen from log4net
|
//stolen from log4net
|
||||||
public const UInt32 STD_OUTPUT_HANDLE = unchecked((UInt32)(-11));
|
/// <summary>
|
||||||
public const UInt32 STD_ERROR_HANDLE = unchecked((UInt32)(-12));
|
/// stdout handle
|
||||||
|
/// </summary>
|
||||||
|
public const uint STD_OUTPUT_HANDLE = unchecked((UInt32)(-11));
|
||||||
|
/// <summary>
|
||||||
|
/// stderr handle
|
||||||
|
/// </summary>
|
||||||
|
public const uint STD_ERROR_HANDLE = unchecked((UInt32)(-12));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new ConsoleLogHandler with a default
|
/// Constructs a new ConsoleLogHandler with a default
|
||||||
/// message handler
|
/// message handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ConsoleLogHandler() {
|
public ConsoleLogHandler() {
|
||||||
this.messageHandler = new DefaultMessageHandler();
|
this.MessageHandler = new DefaultMessageHandler();
|
||||||
this.logLevel = null;
|
this.LogLevel = SimpleLog.Framework.LogLevel.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region ILogHandler Members
|
#region ILogHandler Members
|
||||||
|
/// <summary>
|
||||||
|
/// Gracefully shuts down this log handler
|
||||||
|
/// </summary>
|
||||||
public virtual void GracefulShutDown() {
|
public virtual void GracefulShutDown() {
|
||||||
//does nothing
|
//does nothing
|
||||||
}
|
}
|
||||||
@ -32,7 +47,7 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the log level for this handler
|
/// Gets or sets the log level for this handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogLevel? LogLevel {
|
public LogLevel LogLevel {
|
||||||
get {
|
get {
|
||||||
return this.logLevel;
|
return this.logLevel;
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,37 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum ConsoleColor : int {
|
public enum ConsoleColor : int {
|
||||||
|
/// <summary>
|
||||||
|
/// The color blue
|
||||||
|
/// </summary>
|
||||||
Blue = 0x0001,
|
Blue = 0x0001,
|
||||||
|
/// <summary>
|
||||||
|
/// The color green
|
||||||
|
/// </summary>
|
||||||
Green = 0x0002,
|
Green = 0x0002,
|
||||||
|
/// <summary>
|
||||||
|
/// The color red
|
||||||
|
/// </summary>
|
||||||
Red = 0x0004,
|
Red = 0x0004,
|
||||||
|
/// <summary>
|
||||||
|
/// The color white (Red, Green and Blue combined)
|
||||||
|
/// </summary>
|
||||||
White = Blue | Green | Red,
|
White = Blue | Green | Red,
|
||||||
|
/// <summary>
|
||||||
|
/// The color yellow (Red and Green combined)
|
||||||
|
/// </summary>
|
||||||
Yellow = Red | Green,
|
Yellow = Red | Green,
|
||||||
|
/// <summary>
|
||||||
|
/// The color purple (Red and Blue combined)
|
||||||
|
/// </summary>
|
||||||
Purple = Red | Blue,
|
Purple = Red | Blue,
|
||||||
|
/// <summary>
|
||||||
|
/// The color cyan (Green and Blue combined)
|
||||||
|
/// </summary>
|
||||||
Cyan = Green | Blue,
|
Cyan = Green | Blue,
|
||||||
|
/// <summary>
|
||||||
|
/// Brightens a color
|
||||||
|
/// </summary>
|
||||||
HighIntensity = 0x0008,
|
HighIntensity = 0x0008,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,33 @@ using System.IO;
|
|||||||
using SimpleLog.Framework;
|
using SimpleLog.Framework;
|
||||||
|
|
||||||
namespace SimpleLog.LogHandlers {
|
namespace SimpleLog.LogHandlers {
|
||||||
|
/// <summary>
|
||||||
|
/// Log handler for filesystem-based logging
|
||||||
|
/// </summary>
|
||||||
public class FileLogHandler : ILogHandler {
|
public class FileLogHandler : ILogHandler {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Message handler used by this log handler
|
||||||
|
/// </summary>
|
||||||
protected IMessageHandler messageHandler;
|
protected IMessageHandler messageHandler;
|
||||||
protected LogLevel? logLevel;
|
/// <summary>
|
||||||
|
/// Log level of this log handler
|
||||||
|
/// </summary>
|
||||||
|
protected LogLevel logLevel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Directory in which to create the log files
|
||||||
|
/// </summary>
|
||||||
protected string logDirectory;
|
protected string logDirectory;
|
||||||
|
/// <summary>
|
||||||
|
/// The string that prepends each log file name (e.g.
|
||||||
|
/// in logger_20090417.log, "logger" is the filePrefix)
|
||||||
|
/// </summary>
|
||||||
protected string filePrefix;
|
protected string filePrefix;
|
||||||
|
/// <summary>
|
||||||
|
/// The file extension of each log file (e.g.
|
||||||
|
/// in logger_20090417.log, ".log" is the fileSuffix)
|
||||||
|
/// </summary>
|
||||||
protected string fileSuffix;
|
protected string fileSuffix;
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -30,10 +50,10 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// <param name="suffix">The file suffix (e.g. ".log")</param>
|
/// <param name="suffix">The file suffix (e.g. ".log")</param>
|
||||||
public FileLogHandler(string dir, string prefix, string suffix) {
|
public FileLogHandler(string dir, string prefix, string suffix) {
|
||||||
this.messageHandler = new DefaultMessageHandler();
|
this.messageHandler = new DefaultMessageHandler();
|
||||||
this.logLevel = null;
|
this.LogLevel = SimpleLog.Framework.LogLevel.None;
|
||||||
this.logDirectory = dir;
|
this.LogDirectory = dir;
|
||||||
this.filePrefix = prefix;
|
this.FilePrefix = prefix;
|
||||||
this.fileSuffix = suffix;
|
this.FileSuffix = suffix;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -48,7 +68,7 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the log level
|
/// Gets or sets the log level
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LogLevel? LogLevel {
|
public LogLevel LogLevel {
|
||||||
get {
|
get {
|
||||||
return this.logLevel;
|
return this.logLevel;
|
||||||
}
|
}
|
||||||
@ -94,7 +114,7 @@ namespace SimpleLog.LogHandlers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual string BuildFileName() {
|
protected virtual string BuildFileName() {
|
||||||
string fileName = this.logDirectory + Path.DirectorySeparatorChar + this.FilePrefix;
|
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;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user