Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

ILogger and Fixed unit tests #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NLog/ComInterop/ComLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ namespace NLog.ComInterop
[ClassInterface(ClassInterfaceType.None)]
public class ComLogger : IComLogger
{
private static readonly Logger DefaultLogger = LogManager.CreateNullLogger();
private static readonly ILogger DefaultLogger = LogManager.CreateNullLogger();

private Logger logger = DefaultLogger;
private ILogger logger = DefaultLogger;
private string loggerName = string.Empty;

/// <summary>
Expand Down
957 changes: 957 additions & 0 deletions src/NLog/ILogger.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/NLog/LogFactory-T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace NLog
/// </summary>
/// <typeparam name="T">The type of the logger to be returned. Must inherit from <see cref="Logger"/>.</typeparam>
public class LogFactory<T> : LogFactory
where T : Logger
where T : ILogger
{
/// <summary>
/// Gets the logger.
Expand Down
12 changes: 6 additions & 6 deletions src/NLog/LogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public Logger CreateNullLogger()
/// <remarks>This is a slow-running method.
/// Make sure you're not doing this in a loop.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public Logger GetCurrentClassLogger()
public ILogger GetCurrentClassLogger()
{
#if SILVERLIGHT
var frame = new StackFrame(1);
Expand All @@ -310,7 +310,7 @@ public Logger GetCurrentClassLogger()
/// <remarks>This is a slow-running method.
/// Make sure you're not doing this in a loop.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public Logger GetCurrentClassLogger(Type loggerType)
public ILogger GetCurrentClassLogger(Type loggerType)
{
#if !SILVERLIGHT
var frame = new StackFrame(1, false);
Expand All @@ -327,7 +327,7 @@ public Logger GetCurrentClassLogger(Type loggerType)
/// </summary>
/// <param name="name">Name of the logger.</param>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the same argument aren't guaranteed to return the same logger reference.</returns>
public Logger GetLogger(string name)
public ILogger GetLogger(string name)
{
return this.GetLogger(new LoggerCacheKey(typeof(Logger), name));
}
Expand All @@ -339,7 +339,7 @@ public Logger GetLogger(string name)
/// <param name="loggerType">The type of the logger to create. The type must inherit from NLog.Logger.</param>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the
/// same argument aren't guaranteed to return the same logger reference.</returns>
public Logger GetLogger(string name, Type loggerType)
public ILogger GetLogger(string name, Type loggerType)
{
return this.GetLogger(new LoggerCacheKey(loggerType, name));
}
Expand Down Expand Up @@ -682,15 +682,15 @@ private static void Dump(LoggingConfiguration config)
config.Dump();
}

private Logger GetLogger(LoggerCacheKey cacheKey)
private ILogger GetLogger(LoggerCacheKey cacheKey)
{
lock (this)
{
WeakReference l;

if (this.loggerCache.TryGetValue(cacheKey, out l))
{
Logger existingLogger = l.Target as Logger;
ILogger existingLogger = l.Target as Logger;
if (existingLogger != null)
{
// logger in the cache and still referenced
Expand Down
10 changes: 5 additions & 5 deletions src/NLog/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static LogLevel GlobalThreshold
/// <remarks>This is a slow-running method.
/// Make sure you're not doing this in a loop.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public static Logger GetCurrentClassLogger()
public static ILogger GetCurrentClassLogger()
{
#if SILVERLIGHT
StackFrame frame = new StackTrace().GetFrame(1);
Expand All @@ -151,7 +151,7 @@ public static Logger GetCurrentClassLogger()
/// <remarks>This is a slow-running method.
/// Make sure you're not doing this in a loop.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public static Logger GetCurrentClassLogger(Type loggerType)
public static ILogger GetCurrentClassLogger(Type loggerType)
{
#if SILVERLIGHT
StackFrame frame = new StackTrace().GetFrame(1);
Expand All @@ -166,7 +166,7 @@ public static Logger GetCurrentClassLogger(Type loggerType)
/// Creates a logger that discards all log messages.
/// </summary>
/// <returns>Null logger which discards all log messages.</returns>
public static Logger CreateNullLogger()
public static ILogger CreateNullLogger()
{
return globalFactory.CreateNullLogger();
}
Expand All @@ -176,7 +176,7 @@ public static Logger CreateNullLogger()
/// </summary>
/// <param name="name">Name of the logger.</param>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the same argument aren't guaranteed to return the same logger reference.</returns>
public static Logger GetLogger(string name)
public static ILogger GetLogger(string name)
{
return globalFactory.GetLogger(name);
}
Expand All @@ -187,7 +187,7 @@ public static Logger GetLogger(string name)
/// <param name="name">Name of the logger.</param>
/// <param name="loggerType">The logger class. The class must inherit from <see cref="Logger" />.</param>
/// <returns>The logger reference. Multiple calls to <c>GetLogger</c> with the same argument aren't guaranteed to return the same logger reference.</returns>
public static Logger GetLogger(string name, Type loggerType)
public static ILogger GetLogger(string name, Type loggerType)
{
return globalFactory.GetLogger(name, loggerType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void ProcessLogMessages(NLogEvents events)
/// <param name="logEvents">The log events.</param>
protected virtual void ProcessLogMessages(LogEventInfo[] logEvents)
{
Logger logger = null;
ILogger logger = null;
string lastLoggerName = string.Empty;

foreach (var ev in logEvents)
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace NLog
/// Provides logging interface and utility functions.
/// </summary>
[CLSCompliant(true)]
public partial class Logger
public partial class Logger : NLog.ILogger
{
private readonly Type loggerType = typeof(Logger);

Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.mono2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -313,6 +314,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.monodevelop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -317,6 +318,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netcf20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -319,6 +320,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netcf35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -320,6 +321,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -309,6 +310,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -311,6 +312,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.netfx40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -317,6 +318,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.sl2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -313,6 +314,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.sl3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -313,6 +314,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.sl4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -314,6 +315,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/NLog.wp7.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="GDC.cs" />
<Compile Include="GlobalDiagnosticsContext.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ILogger.cs" />
<Compile Include="Internal\AspHelper.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -316,6 +317,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/NLog/NLog.wp71.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
<Compile Include="Targets\DebuggerTarget.cs" />
<Compile Include="Targets\DebugTarget.cs" />
<Compile Include="Targets\EventLogTarget.cs" />
<Compile Include="Targets\FileArchiveAboveSizeUnit.cs" />
<Compile Include="Targets\FileArchivePeriod.cs" />
<Compile Include="Targets\FileTarget.cs" />
<Compile Include="Targets\FormControlTarget.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/NLogTraceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private void ProcessLogEventInfo(LogLevel logLevel, string loggerName, [Localiza
ev.Properties.Add("EventID", eventId.Value);
}

Logger logger = LogManager.GetLogger(ev.LoggerName);
ILogger logger = LogManager.GetLogger(ev.LoggerName);
logger.Log(ev);
}

Expand Down
61 changes: 61 additions & 0 deletions src/NLog/Targets/FileArchiveAboveSizeUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright (c) 2004-2011 Jaroslaw Kowalski <jaak@jkowalski.net>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of Jaroslaw Kowalski nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//

namespace NLog.Targets
{
/// <summary>
/// Modes of archiving files based on time.
/// </summary>
public enum FileArchiveAboveSizeUnit
{
/// <summary>
/// Archive based on size specified in bytes
/// </summary>
B,

/// <summary>
/// Archive based on size specified in kilobytes
/// </summary>
KB,

/// <summary>
/// Archive based on size specified in megabytes
/// </summary>
MB,

/// <summary>
/// Archive based on size specified in gigabytes
/// </summary>
GB
}
}
Loading