From 8d3f76794e458ec3aa7b10bd5b75fe56ba0614b4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Nov 2011 22:06:24 +0100 Subject: [PATCH 1/4] Added interface ILogger and fixed some failing unit test that were culture specific --- src/NLog/ComInterop/ComLogger.cs | 4 +- src/NLog/ILogger.cs | 962 ++++++++++++++++++ src/NLog/LogFactory-T.cs | 2 +- src/NLog/LogFactory.cs | 12 +- src/NLog/LogManager.cs | 10 +- .../LogReceiverForwardingService.cs | 2 +- src/NLog/Logger.cs | 2 +- src/NLog/NLog.mono2.csproj | 1 + src/NLog/NLog.monodevelop.csproj | 1 + src/NLog/NLog.netcf20.csproj | 1 + src/NLog/NLog.netcf35.csproj | 1 + src/NLog/NLog.netfx20.csproj | 1 + src/NLog/NLog.netfx35.csproj | 1 + src/NLog/NLog.netfx40.csproj | 1 + src/NLog/NLog.sl2.csproj | 1 + src/NLog/NLog.sl3.csproj | 1 + src/NLog/NLog.sl4.csproj | 1 + src/NLog/NLog.wp7.csproj | 1 + src/NLog/NLogTraceListener.cs | 2 +- src/NLogC/NLogC.cpp | 8 +- tests/NLog.Test/Test.cs | 2 +- .../Config/CaseSensitivityTests.cs | 4 +- .../NLog.UnitTests/ConfigFileLocatorTests.cs | 2 +- .../Filters/ConditionBasedFilterTests.cs | 2 +- .../Filters/WhenContainsTests.cs | 4 +- .../NLog.UnitTests/Filters/WhenEqualTests.cs | 4 +- .../Filters/WhenNotContainsTests.cs | 4 +- .../Filters/WhenNotEqualTests.cs | 4 +- tests/NLog.UnitTests/GetLoggerTests.cs | 18 +- .../LayoutRenderers/CallSiteTests.cs | 10 +- .../LayoutRenderers/CounterTests.cs | 4 +- .../LayoutRenderers/DateTests.cs | 5 + .../LayoutRenderers/ExceptionTests.cs | 2 +- .../LayoutRenderers/LiteralTests.cs | 2 +- .../LayoutRenderers/Log4JXmlTests.cs | 2 +- .../LayoutRenderers/LogLevelTests.cs | 2 +- .../LayoutRenderers/LoggerNameTests.cs | 2 +- .../LayoutRenderers/MessageTests.cs | 14 +- .../LayoutRenderers/Rot13Tests.cs | 2 +- .../NLog.UnitTests/Layouts/CsvLayoutTests.cs | 14 +- tests/NLog.UnitTests/LogManagerTests.cs | 14 +- tests/NLog.UnitTests/LoggerTests.cs | 16 +- .../NLog.UnitTests/NLogTraceListenerTests.cs | 12 +- tests/NLog.UnitTests/RegressionTests.cs | 2 +- tests/NLog.UnitTests/RoutingTests.cs | 4 +- .../Targets/ConcurrentFileTargetTests.cs | 2 +- tests/NLog.UnitTests/Targets/EventLogTests.cs | 2 +- .../NLog.UnitTests/Targets/FileTargetTests.cs | 2 +- .../Targets/RichTextBoxTargetTests.cs | 5 +- 49 files changed, 1087 insertions(+), 90 deletions(-) create mode 100644 src/NLog/ILogger.cs diff --git a/src/NLog/ComInterop/ComLogger.cs b/src/NLog/ComInterop/ComLogger.cs index bcaf5e2d..0ce1cdbc 100644 --- a/src/NLog/ComInterop/ComLogger.cs +++ b/src/NLog/ComInterop/ComLogger.cs @@ -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; /// diff --git a/src/NLog/ILogger.cs b/src/NLog/ILogger.cs new file mode 100644 index 00000000..9985e47c --- /dev/null +++ b/src/NLog/ILogger.cs @@ -0,0 +1,962 @@ +// +// Copyright (c) 2004-2011 Jaroslaw Kowalski +// +// 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 +{ + using System; + using System.ComponentModel; + + /// + /// Provides the interface for the logging interface + /// + public interface ILogger + { + /// + /// Occurs when logger configuration changes. + /// + event EventHandler LoggerReconfigured; + + /// + /// Gets the name of the logger. + /// + string Name { get; } + + /// + /// Gets the factory that created this logger. + /// + LogFactory Factory { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Trace level. + /// + /// A value of if logging is enabled for the Trace level, otherwise it returns . + bool IsTraceEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Debug level. + /// + /// A value of if logging is enabled for the Debug level, otherwise it returns . + bool IsDebugEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Info level. + /// + /// A value of if logging is enabled for the Info level, otherwise it returns . + bool IsInfoEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Warn level. + /// + /// A value of if logging is enabled for the Warn level, otherwise it returns . + bool IsWarnEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Error level. + /// + /// A value of if logging is enabled for the Error level, otherwise it returns . + bool IsErrorEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the Fatal level. + /// + /// A value of if logging is enabled for the Fatal level, otherwise it returns . + bool IsFatalEnabled { get; } + + /// + /// Gets a value indicating whether logging is enabled for the specified level. + /// + /// Log level to be checked. + /// A value of if logging is enabled for the specified level, otherwise it returns . + bool IsEnabled(LogLevel level); + + /// + /// Writes the specified diagnostic message. + /// + /// Log event. + void Log(LogEventInfo logEvent); + + /// + /// Writes the specified diagnostic message. + /// + /// The name of the type that wraps Logger. + /// Log event. + void Log(Type wrapperType, LogEventInfo logEvent); + + // the following code has been automatically generated by a PERL script + #region Log() overloads + + /// + /// Writes the diagnostic message at the specified level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the specified level. + /// + /// Type of the value. + /// The log level. + /// The value to be written. + void Log(LogLevel level, T value); + + /// + /// Writes the diagnostic message at the specified level. + /// + /// Type of the value. + /// The log level. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Log(LogLevel level, IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the specified level. + /// + /// The log level. + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Log(LogLevel level, LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the specified level. + /// + /// The log level. + /// A to be written. + /// An exception to be logged. + void LogException(LogLevel level, [Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the specified level using the specified parameters and formatting them with the supplied format provider. + /// + /// The log level. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the specified level. + /// + /// The log level. + /// Log message. + void Log(LogLevel level, [Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the specified level using the specified parameters. + /// + /// The log level. + /// A containing format items. + /// Arguments to format. + void Log(LogLevel level, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the specified level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// The log level. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the specified level using the specified parameter. + /// + /// The type of the argument. + /// The log level. + /// A containing one format item. + /// The argument to format. + void Log(LogLevel level, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the specified level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The log level. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the specified level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The log level. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Log(LogLevel level, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the specified level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// The log level. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the specified level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// The log level. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Log(LogLevel level, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Trace() overloads + + /// + /// Writes the diagnostic message at the Trace level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Trace level. + /// + /// Type of the value. + /// The value to be written. + void Trace(T value); + + /// + /// Writes the diagnostic message at the Trace level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Trace(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Trace level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Trace(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Trace level. + /// + /// A to be written. + /// An exception to be logged. + void TraceException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Trace(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Trace level. + /// + /// Log message. + void Trace([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Trace([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Trace(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Trace([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Trace level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Trace(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Trace([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Trace level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Trace(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Trace level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Trace([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Debug() overloads + + /// + /// Writes the diagnostic message at the Debug level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Debug level. + /// + /// Type of the value. + /// The value to be written. + void Debug(T value); + + /// + /// Writes the diagnostic message at the Debug level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Debug(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Debug level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Debug(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Debug level. + /// + /// A to be written. + /// An exception to be logged. + void DebugException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Debug level. + /// + /// Log message. + void Debug([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Debug([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Debug([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Debug level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Debug([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Debug level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Debug(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Debug level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Debug([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Info() overloads + + /// + /// Writes the diagnostic message at the Info level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Info level. + /// + /// Type of the value. + /// The value to be written. + void Info(T value); + + /// + /// Writes the diagnostic message at the Info level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Info(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Info level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Info(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Info level. + /// + /// A to be written. + /// An exception to be logged. + void InfoException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Info level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Info level. + /// + /// Log message. + void Info([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Info level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Info([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Info level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Info level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Info([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Info level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Info level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Info([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Info level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Info(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Info level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Info([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Warn() overloads + + /// + /// Writes the diagnostic message at the Warn level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Warn level. + /// + /// Type of the value. + /// The value to be written. + void Warn(T value); + + /// + /// Writes the diagnostic message at the Warn level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Warn(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Warn level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Warn(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Warn level. + /// + /// A to be written. + /// An exception to be logged. + void WarnException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Warn level. + /// + /// Log message. + void Warn([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Warn([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Warn([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Warn level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Warn([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Warn level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Warn(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Warn level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Warn([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Error() overloads + + /// + /// Writes the diagnostic message at the Error level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Error level. + /// + /// Type of the value. + /// The value to be written. + void Error(T value); + + /// + /// Writes the diagnostic message at the Error level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Error(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Error level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Error(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Error level. + /// + /// A to be written. + /// An exception to be logged. + void ErrorException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Error level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Error level. + /// + /// Log message. + void Error([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Error level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Error([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Error level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Error level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Error([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Error level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Error level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Error([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Error level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Error(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Error level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Error([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + + #region Fatal() overloads + + /// + /// Writes the diagnostic message at the Fatal level using the specified format provider and format parameters. + /// + /// + /// Writes the diagnostic message at the Fatal level. + /// + /// Type of the value. + /// The value to be written. + void Fatal(T value); + + /// + /// Writes the diagnostic message at the Fatal level. + /// + /// Type of the value. + /// An IFormatProvider that supplies culture-specific formatting information. + /// The value to be written. + void Fatal(IFormatProvider formatProvider, T value); + + /// + /// Writes the diagnostic message at the Fatal level. + /// + /// A function returning message to be written. Function is not evaluated if logging is not enabled. + void Fatal(LogMessageGenerator messageFunc); + + /// + /// Writes the diagnostic message and exception at the Fatal level. + /// + /// A to be written. + /// An exception to be logged. + void FatalException([Localizable(false)] string message, Exception exception); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameters and formatting them with the supplied format provider. + /// + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing format items. + /// Arguments to format. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Fatal level. + /// + /// Log message. + void Fatal([Localizable(false)] string message); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameters. + /// + /// A containing format items. + /// Arguments to format. + void Fatal([Localizable(false)] string message, params object[] args); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameter and formatting it with the supplied format provider. + /// + /// The type of the argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The argument to format. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameter. + /// + /// The type of the argument. + /// A containing one format item. + /// The argument to format. + void Fatal([Localizable(false)] string message, TArgument argument); + + /// + /// Writes the diagnostic message at the Fatal level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + void Fatal([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2); + + /// + /// Writes the diagnostic message at the Fatal level using the specified arguments formatting it with the supplied format provider. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// An IFormatProvider that supplies culture-specific formatting information. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Fatal(IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + /// + /// Writes the diagnostic message at the Fatal level using the specified parameters. + /// + /// The type of the first argument. + /// The type of the second argument. + /// The type of the third argument. + /// A containing one format item. + /// The first argument to format. + /// The second argument to format. + /// The third argument to format. + void Fatal([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3); + + #endregion + } +} diff --git a/src/NLog/LogFactory-T.cs b/src/NLog/LogFactory-T.cs index 70c22e96..b53b2930 100644 --- a/src/NLog/LogFactory-T.cs +++ b/src/NLog/LogFactory-T.cs @@ -41,7 +41,7 @@ namespace NLog /// /// The type of the logger to be returned. Must inherit from . public class LogFactory : LogFactory - where T : Logger + where T : ILogger { /// /// Gets the logger. diff --git a/src/NLog/LogFactory.cs b/src/NLog/LogFactory.cs index eac8631d..a5e68dc6 100644 --- a/src/NLog/LogFactory.cs +++ b/src/NLog/LogFactory.cs @@ -291,7 +291,7 @@ public Logger CreateNullLogger() /// This is a slow-running method. /// Make sure you're not doing this in a loop. [MethodImpl(MethodImplOptions.NoInlining)] - public Logger GetCurrentClassLogger() + public ILogger GetCurrentClassLogger() { #if SILVERLIGHT var frame = new StackFrame(1); @@ -310,7 +310,7 @@ public Logger GetCurrentClassLogger() /// This is a slow-running method. /// Make sure you're not doing this in a loop. [MethodImpl(MethodImplOptions.NoInlining)] - public Logger GetCurrentClassLogger(Type loggerType) + public ILogger GetCurrentClassLogger(Type loggerType) { #if !SILVERLIGHT var frame = new StackFrame(1, false); @@ -327,7 +327,7 @@ public Logger GetCurrentClassLogger(Type loggerType) /// /// Name of the logger. /// The logger reference. Multiple calls to GetLogger with the same argument aren't guaranteed to return the same logger reference. - public Logger GetLogger(string name) + public ILogger GetLogger(string name) { return this.GetLogger(new LoggerCacheKey(typeof(Logger), name)); } @@ -339,7 +339,7 @@ public Logger GetLogger(string name) /// The type of the logger to create. The type must inherit from NLog.Logger. /// The logger reference. Multiple calls to GetLogger with the /// same argument aren't guaranteed to return the same logger reference. - public Logger GetLogger(string name, Type loggerType) + public ILogger GetLogger(string name, Type loggerType) { return this.GetLogger(new LoggerCacheKey(loggerType, name)); } @@ -682,7 +682,7 @@ private static void Dump(LoggingConfiguration config) config.Dump(); } - private Logger GetLogger(LoggerCacheKey cacheKey) + private ILogger GetLogger(LoggerCacheKey cacheKey) { lock (this) { @@ -690,7 +690,7 @@ private Logger GetLogger(LoggerCacheKey cacheKey) 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 diff --git a/src/NLog/LogManager.cs b/src/NLog/LogManager.cs index e9b9706d..c3d44e2d 100644 --- a/src/NLog/LogManager.cs +++ b/src/NLog/LogManager.cs @@ -132,7 +132,7 @@ public static LogLevel GlobalThreshold /// This is a slow-running method. /// Make sure you're not doing this in a loop. [MethodImpl(MethodImplOptions.NoInlining)] - public static Logger GetCurrentClassLogger() + public static ILogger GetCurrentClassLogger() { #if SILVERLIGHT StackFrame frame = new StackTrace().GetFrame(1); @@ -151,7 +151,7 @@ public static Logger GetCurrentClassLogger() /// This is a slow-running method. /// Make sure you're not doing this in a loop. [MethodImpl(MethodImplOptions.NoInlining)] - public static Logger GetCurrentClassLogger(Type loggerType) + public static ILogger GetCurrentClassLogger(Type loggerType) { #if SILVERLIGHT StackFrame frame = new StackTrace().GetFrame(1); @@ -166,7 +166,7 @@ public static Logger GetCurrentClassLogger(Type loggerType) /// Creates a logger that discards all log messages. /// /// Null logger which discards all log messages. - public static Logger CreateNullLogger() + public static ILogger CreateNullLogger() { return globalFactory.CreateNullLogger(); } @@ -176,7 +176,7 @@ public static Logger CreateNullLogger() /// /// Name of the logger. /// The logger reference. Multiple calls to GetLogger with the same argument aren't guaranteed to return the same logger reference. - public static Logger GetLogger(string name) + public static ILogger GetLogger(string name) { return globalFactory.GetLogger(name); } @@ -187,7 +187,7 @@ public static Logger GetLogger(string name) /// Name of the logger. /// The logger class. The class must inherit from . /// The logger reference. Multiple calls to GetLogger with the same argument aren't guaranteed to return the same logger reference. - public static Logger GetLogger(string name, Type loggerType) + public static ILogger GetLogger(string name, Type loggerType) { return globalFactory.GetLogger(name, loggerType); } diff --git a/src/NLog/LogReceiverService/LogReceiverForwardingService.cs b/src/NLog/LogReceiverService/LogReceiverForwardingService.cs index e97e17ac..9d4cb1bd 100644 --- a/src/NLog/LogReceiverService/LogReceiverForwardingService.cs +++ b/src/NLog/LogReceiverService/LogReceiverForwardingService.cs @@ -101,7 +101,7 @@ public void ProcessLogMessages(NLogEvents events) /// The log events. protected virtual void ProcessLogMessages(LogEventInfo[] logEvents) { - Logger logger = null; + ILogger logger = null; string lastLoggerName = string.Empty; foreach (var ev in logEvents) diff --git a/src/NLog/Logger.cs b/src/NLog/Logger.cs index 684852f3..9c7cddd1 100644 --- a/src/NLog/Logger.cs +++ b/src/NLog/Logger.cs @@ -41,7 +41,7 @@ namespace NLog /// Provides logging interface and utility functions. /// [CLSCompliant(true)] - public partial class Logger + public partial class Logger : NLog.ILogger { private readonly Type loggerType = typeof(Logger); diff --git a/src/NLog/NLog.mono2.csproj b/src/NLog/NLog.mono2.csproj index b35bc4c6..f78eef73 100644 --- a/src/NLog/NLog.mono2.csproj +++ b/src/NLog/NLog.mono2.csproj @@ -129,6 +129,7 @@ + true diff --git a/src/NLog/NLog.monodevelop.csproj b/src/NLog/NLog.monodevelop.csproj index 8feaac17..caacff7b 100644 --- a/src/NLog/NLog.monodevelop.csproj +++ b/src/NLog/NLog.monodevelop.csproj @@ -133,6 +133,7 @@ + true diff --git a/src/NLog/NLog.netcf20.csproj b/src/NLog/NLog.netcf20.csproj index df3508a3..2cf04f36 100644 --- a/src/NLog/NLog.netcf20.csproj +++ b/src/NLog/NLog.netcf20.csproj @@ -135,6 +135,7 @@ + true diff --git a/src/NLog/NLog.netcf35.csproj b/src/NLog/NLog.netcf35.csproj index b8a1dc29..c4824d7e 100644 --- a/src/NLog/NLog.netcf35.csproj +++ b/src/NLog/NLog.netcf35.csproj @@ -136,6 +136,7 @@ + true diff --git a/src/NLog/NLog.netfx20.csproj b/src/NLog/NLog.netfx20.csproj index f3f5dc8e..39e0b260 100644 --- a/src/NLog/NLog.netfx20.csproj +++ b/src/NLog/NLog.netfx20.csproj @@ -125,6 +125,7 @@ + true diff --git a/src/NLog/NLog.netfx35.csproj b/src/NLog/NLog.netfx35.csproj index da320557..c4264f35 100644 --- a/src/NLog/NLog.netfx35.csproj +++ b/src/NLog/NLog.netfx35.csproj @@ -127,6 +127,7 @@ + true diff --git a/src/NLog/NLog.netfx40.csproj b/src/NLog/NLog.netfx40.csproj index 0572b299..67c241f1 100644 --- a/src/NLog/NLog.netfx40.csproj +++ b/src/NLog/NLog.netfx40.csproj @@ -133,6 +133,7 @@ + true diff --git a/src/NLog/NLog.sl2.csproj b/src/NLog/NLog.sl2.csproj index b5e7289d..0324f200 100644 --- a/src/NLog/NLog.sl2.csproj +++ b/src/NLog/NLog.sl2.csproj @@ -129,6 +129,7 @@ + true diff --git a/src/NLog/NLog.sl3.csproj b/src/NLog/NLog.sl3.csproj index 08e941f8..3ccf175c 100644 --- a/src/NLog/NLog.sl3.csproj +++ b/src/NLog/NLog.sl3.csproj @@ -129,6 +129,7 @@ + true diff --git a/src/NLog/NLog.sl4.csproj b/src/NLog/NLog.sl4.csproj index 1aacdbb4..57b84705 100644 --- a/src/NLog/NLog.sl4.csproj +++ b/src/NLog/NLog.sl4.csproj @@ -130,6 +130,7 @@ + true diff --git a/src/NLog/NLog.wp7.csproj b/src/NLog/NLog.wp7.csproj index a0396a17..cbef5768 100644 --- a/src/NLog/NLog.wp7.csproj +++ b/src/NLog/NLog.wp7.csproj @@ -132,6 +132,7 @@ + true diff --git a/src/NLog/NLogTraceListener.cs b/src/NLog/NLogTraceListener.cs index 7e42ec7d..a3526487 100644 --- a/src/NLog/NLogTraceListener.cs +++ b/src/NLog/NLogTraceListener.cs @@ -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); } diff --git a/src/NLogC/NLogC.cpp b/src/NLogC/NLogC.cpp index 6ba4249e..55ce68da 100644 --- a/src/NLogC/NLogC.cpp +++ b/src/NLogC/NLogC.cpp @@ -51,7 +51,7 @@ using namespace NLog; static void WriteToA(NLogLevel level, const char * loggerName, const char * messageBuffer) { - Logger ^logger = LogManager::GetLogger(gcnew String(loggerName)); + ILogger ^logger = LogManager::GetLogger(gcnew String(loggerName)); switch (level) { @@ -84,7 +84,7 @@ static void WriteToA(NLogLevel level, const char * loggerName, const char * mess static void WriteToW(NLogLevel level, const wchar_t * loggerName, const wchar_t * messageBuffer) { - Logger ^logger = LogManager::GetLogger(gcnew String(loggerName)); + ILogger ^logger = LogManager::GetLogger(gcnew String(loggerName)); switch (level) { @@ -117,7 +117,7 @@ static void WriteToW(NLogLevel level, const wchar_t * loggerName, const wchar_t static bool IsLogEnabledA(NLogLevel level, const char * loggerName) { - Logger ^logger = LogManager::GetLogger(gcnew String(loggerName)); + ILogger ^logger = LogManager::GetLogger(gcnew String(loggerName)); switch (level) { case NLOG_TRACE: @@ -145,7 +145,7 @@ static bool IsLogEnabledA(NLogLevel level, const char * loggerName) static bool IsLogEnabledW(NLogLevel level, const wchar_t * loggerName) { - Logger ^logger = LogManager::GetLogger(gcnew String(loggerName)); + ILogger ^logger = LogManager::GetLogger(gcnew String(loggerName)); switch (level) { case NLOG_TRACE: diff --git a/tests/NLog.Test/Test.cs b/tests/NLog.Test/Test.cs index 4057ee69..197e2a36 100644 --- a/tests/NLog.Test/Test.cs +++ b/tests/NLog.Test/Test.cs @@ -45,7 +45,7 @@ public static class ExtensionMethods public class Test { - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); public static void LogProc(string msg) { diff --git a/tests/NLog.UnitTests/Config/CaseSensitivityTests.cs b/tests/NLog.UnitTests/Config/CaseSensitivityTests.cs index 49717824..961182b0 100644 --- a/tests/NLog.UnitTests/Config/CaseSensitivityTests.cs +++ b/tests/NLog.UnitTests/Config/CaseSensitivityTests.cs @@ -60,7 +60,7 @@ public void LowerCaseTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); logger.Info("msg"); logger.Warn("msg"); @@ -97,7 +97,7 @@ public void UpperCaseTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); logger.Info("msg"); logger.Warn("msg"); diff --git a/tests/NLog.UnitTests/ConfigFileLocatorTests.cs b/tests/NLog.UnitTests/ConfigFileLocatorTests.cs index 4fd1f5ac..e6371217 100644 --- a/tests/NLog.UnitTests/ConfigFileLocatorTests.cs +++ b/tests/NLog.UnitTests/ConfigFileLocatorTests.cs @@ -287,7 +287,7 @@ private static string RunTestIn(string directory) class C1 { - private static Logger logger = LogManager.GetCurrentClassLogger(); + private static ILogger logger = LogManager.GetCurrentClassLogger(); static void Main(string[] args) { diff --git a/tests/NLog.UnitTests/Filters/ConditionBasedFilterTests.cs b/tests/NLog.UnitTests/Filters/ConditionBasedFilterTests.cs index 163ba7a4..81d70721 100644 --- a/tests/NLog.UnitTests/Filters/ConditionBasedFilterTests.cs +++ b/tests/NLog.UnitTests/Filters/ConditionBasedFilterTests.cs @@ -68,7 +68,7 @@ public void WhenTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 1); logger.Debug("zzz"); diff --git a/tests/NLog.UnitTests/Filters/WhenContainsTests.cs b/tests/NLog.UnitTests/Filters/WhenContainsTests.cs index a1e5549a..5fc23060 100644 --- a/tests/NLog.UnitTests/Filters/WhenContainsTests.cs +++ b/tests/NLog.UnitTests/Filters/WhenContainsTests.cs @@ -68,7 +68,7 @@ public void WhenContainsTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 1); logger.Debug("zzz"); @@ -92,7 +92,7 @@ public void WhenContainsInsensitiveTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 1); logger.Debug("zzz"); diff --git a/tests/NLog.UnitTests/Filters/WhenEqualTests.cs b/tests/NLog.UnitTests/Filters/WhenEqualTests.cs index 94f0ba23..ba605b15 100644 --- a/tests/NLog.UnitTests/Filters/WhenEqualTests.cs +++ b/tests/NLog.UnitTests/Filters/WhenEqualTests.cs @@ -68,7 +68,7 @@ public void WhenEqualTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 1); logger.Debug("skipme"); @@ -92,7 +92,7 @@ public void WhenEqualInsensitiveTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 1); logger.Debug("skipMeToo"); diff --git a/tests/NLog.UnitTests/Filters/WhenNotContainsTests.cs b/tests/NLog.UnitTests/Filters/WhenNotContainsTests.cs index 0abdcfeb..28593985 100644 --- a/tests/NLog.UnitTests/Filters/WhenNotContainsTests.cs +++ b/tests/NLog.UnitTests/Filters/WhenNotContainsTests.cs @@ -68,7 +68,7 @@ public void WhenNotContainsTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 0); logger.Debug("zzz"); @@ -92,7 +92,7 @@ public void WhenNotContainsInsensitiveTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 0); logger.Debug("zzz"); diff --git a/tests/NLog.UnitTests/Filters/WhenNotEqualTests.cs b/tests/NLog.UnitTests/Filters/WhenNotEqualTests.cs index c4b8ff9c..e0865d3c 100644 --- a/tests/NLog.UnitTests/Filters/WhenNotEqualTests.cs +++ b/tests/NLog.UnitTests/Filters/WhenNotEqualTests.cs @@ -68,7 +68,7 @@ public void WhenNotEqualTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 0); logger.Debug("skipme"); @@ -92,7 +92,7 @@ public void WhenNotEqualInsensitiveTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugCounter("debug", 0); logger.Debug("skipMeToo"); diff --git a/tests/NLog.UnitTests/GetLoggerTests.cs b/tests/NLog.UnitTests/GetLoggerTests.cs index 0808c401..ca5e617e 100644 --- a/tests/NLog.UnitTests/GetLoggerTests.cs +++ b/tests/NLog.UnitTests/GetLoggerTests.cs @@ -49,7 +49,7 @@ public class GetLoggerTests : NLogTestBase [Test] public void GetCurrentClassLoggerTest() { - Logger logger = LogManager.GetCurrentClassLogger(); + ILogger logger = LogManager.GetCurrentClassLogger(); Assert.AreEqual("NLog.UnitTests.GetLoggerTests", logger.Name); } @@ -62,10 +62,10 @@ public void TypedGetLoggerTest() MyLogger l1 = (MyLogger)lf.GetLogger("AAA", typeof(MyLogger)); MyLogger l2 = (MyLogger)lf.GetLogger("AAA", typeof(MyLogger)); - Logger l3 = lf.GetLogger("AAA", typeof(Logger)); - Logger l4 = lf.GetLogger("AAA", typeof(Logger)); - Logger l5 = lf.GetLogger("AAA"); - Logger l6 = lf.GetLogger("AAA"); + ILogger l3 = lf.GetLogger("AAA", typeof(Logger)); + ILogger l4 = lf.GetLogger("AAA", typeof(Logger)); + ILogger l5 = lf.GetLogger("AAA"); + ILogger l6 = lf.GetLogger("AAA"); Assert.AreSame(l1, l2); Assert.AreSame(l3, l4); @@ -86,10 +86,10 @@ public void TypedGetCurrentClassLoggerTest() MyLogger l1 = (MyLogger)lf.GetCurrentClassLogger(typeof(MyLogger)); MyLogger l2 = (MyLogger)lf.GetCurrentClassLogger(typeof(MyLogger)); - Logger l3 = lf.GetCurrentClassLogger(typeof(Logger)); - Logger l4 = lf.GetCurrentClassLogger(typeof(Logger)); - Logger l5 = lf.GetCurrentClassLogger(); - Logger l6 = lf.GetCurrentClassLogger(); + ILogger l3 = lf.GetCurrentClassLogger(typeof(Logger)); + ILogger l4 = lf.GetCurrentClassLogger(typeof(Logger)); + ILogger l5 = lf.GetCurrentClassLogger(); + ILogger l6 = lf.GetCurrentClassLogger(); Assert.AreSame(l1, l2); Assert.AreSame(l3, l4); diff --git a/tests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs b/tests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs index 7b52314e..5ca440f5 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/CallSiteTests.cs @@ -68,7 +68,7 @@ public void LineNumberTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); #line 100000 logger.Debug("msg"); string lastMessage = GetDebugLastMessage("debug"); @@ -90,7 +90,7 @@ public void MethodNameTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); MethodBase currentMethod = MethodBase.GetCurrentMethod(); AssertDebugLastMessage("debug", currentMethod.DeclaringType.FullName + "." + currentMethod.Name + " msg"); @@ -107,7 +107,7 @@ public void ClassNameTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); MethodBase currentMethod = MethodBase.GetCurrentMethod(); AssertDebugLastMessage("debug", currentMethod.DeclaringType.FullName + " msg"); @@ -124,7 +124,7 @@ public void ClassNameWithPaddingTestTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); MethodBase currentMethod = MethodBase.GetCurrentMethod(); AssertDebugLastMessage("debug", currentMethod.DeclaringType.FullName.Substring(0, 3) + " msg"); @@ -141,7 +141,7 @@ public void MethodNameWithPaddingTestTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); AssertDebugLastMessage("debug", "MethodNameWithPa msg"); } diff --git a/tests/NLog.UnitTests/LayoutRenderers/CounterTests.cs b/tests/NLog.UnitTests/LayoutRenderers/CounterTests.cs index 869da146..37d55019 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/CounterTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/CounterTests.cs @@ -63,7 +63,7 @@ public void DefaultCounterTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); logger.Info("a"); AssertDebugLastMessage("debug", "a 1 1"); @@ -86,7 +86,7 @@ public void PresetCounterTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); logger.Info("a"); AssertDebugLastMessage("debug", "a 1 1"); diff --git a/tests/NLog.UnitTests/LayoutRenderers/DateTests.cs b/tests/NLog.UnitTests/LayoutRenderers/DateTests.cs index d2eb9264..e2cb4f29 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/DateTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/DateTests.cs @@ -50,6 +50,8 @@ namespace NLog.UnitTests.LayoutRenderers { using NLog.LayoutRenderers; + using System.Threading; + using System.Globalization; [TestFixture] public class DateTests : NLogTestBase @@ -66,6 +68,9 @@ public void DefaultDateTest() "); LogManager.GetLogger("d").Debug("zzz"); +#if !NET_CF + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); +#endif DateTime dt = DateTime.Parse(GetDebugLastMessage("debug")); DateTime now = DateTime.Now; diff --git a/tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs b/tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs index b02cb5b9..e31b808d 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/ExceptionTests.cs @@ -57,7 +57,7 @@ namespace NLog.UnitTests.LayoutRenderers [TestFixture] public class ExceptionTests : NLogTestBase { - private Logger logger = LogManager.GetLogger("NLog.UnitTests.LayoutRenderer.ExceptionTests"); + private ILogger logger = LogManager.GetLogger("NLog.UnitTests.LayoutRenderer.ExceptionTests"); [Test] public void ExceptionWithStackTraceTest() diff --git a/tests/NLog.UnitTests/LayoutRenderers/LiteralTests.cs b/tests/NLog.UnitTests/LayoutRenderers/LiteralTests.cs index 73550a3d..844a40df 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/LiteralTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/LiteralTests.cs @@ -64,7 +64,7 @@ public void LiteralTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "abcd"); } diff --git a/tests/NLog.UnitTests/LayoutRenderers/Log4JXmlTests.cs b/tests/NLog.UnitTests/LayoutRenderers/Log4JXmlTests.cs index 9c92b7e5..c10b5afb 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/Log4JXmlTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/Log4JXmlTests.cs @@ -80,7 +80,7 @@ public void Log4JXmlTest() NestedDiagnosticsContext.Push("baz2"); NestedDiagnosticsContext.Push("baz3"); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("some message"); string result = GetDebugLastMessage("debug"); string wrappedResult = "" + result + ""; diff --git a/tests/NLog.UnitTests/LayoutRenderers/LogLevelTests.cs b/tests/NLog.UnitTests/LayoutRenderers/LogLevelTests.cs index bf9522ea..d43056f2 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/LogLevelTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/LogLevelTests.cs @@ -64,7 +64,7 @@ public void LogLevelTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "Debug a"); logger.Info("a"); diff --git a/tests/NLog.UnitTests/LayoutRenderers/LoggerNameTests.cs b/tests/NLog.UnitTests/LayoutRenderers/LoggerNameTests.cs index 0e7a0006..318c5d37 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/LoggerNameTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/LoggerNameTests.cs @@ -63,7 +63,7 @@ public void LoggerNameTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "A a"); } diff --git a/tests/NLog.UnitTests/LayoutRenderers/MessageTests.cs b/tests/NLog.UnitTests/LayoutRenderers/MessageTests.cs index 9e267611..477bc558 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/MessageTests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/MessageTests.cs @@ -65,7 +65,7 @@ public void MessageWithoutPaddingTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "a"); logger.Debug("a{0}", 1); @@ -87,7 +87,7 @@ public void MessageRightPaddingTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", " a"); logger.Debug("a{0}", 1); @@ -110,7 +110,7 @@ public void MessageFixedLengthRightPaddingTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", " a"); logger.Debug("a{0}", 1); @@ -132,7 +132,7 @@ public void MessageLeftPaddingTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "axx"); logger.Debug("a{0}", 1); @@ -154,7 +154,7 @@ public void MessageFixedLengthLeftPaddingTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "axx"); logger.Debug("a{0}", 1); @@ -176,7 +176,7 @@ public void MessageWithExceptionTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "a"); @@ -202,7 +202,7 @@ public void MessageWithExceptionAndCustomSeparatorTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("a"); AssertDebugLastMessage("debug", "a"); diff --git a/tests/NLog.UnitTests/LayoutRenderers/Rot13Tests.cs b/tests/NLog.UnitTests/LayoutRenderers/Rot13Tests.cs index 912ce36c..160328d0 100644 --- a/tests/NLog.UnitTests/LayoutRenderers/Rot13Tests.cs +++ b/tests/NLog.UnitTests/LayoutRenderers/Rot13Tests.cs @@ -109,7 +109,7 @@ public void Test5() "); MappedDiagnosticsContext.Set("A", "Foo.Bar!"); - Logger l = LogManager.GetLogger("NLog.UnitTests.LayoutRenderers.Rot13Tests"); + ILogger l = LogManager.GetLogger("NLog.UnitTests.LayoutRenderers.Rot13Tests"); l.Trace("aaa"); AssertDebugLastMessage("debug", "Sbb.One!"); diff --git a/tests/NLog.UnitTests/Layouts/CsvLayoutTests.cs b/tests/NLog.UnitTests/Layouts/CsvLayoutTests.cs index 19ccf2ab..32b47d99 100644 --- a/tests/NLog.UnitTests/Layouts/CsvLayoutTests.cs +++ b/tests/NLog.UnitTests/Layouts/CsvLayoutTests.cs @@ -46,6 +46,7 @@ namespace NLog.UnitTests.Layouts using TearDown = Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute; #endif using NLog.Layouts; + using System.Threading; [TestFixture] public class CsvLayoutTests : NLogTestBase @@ -54,6 +55,10 @@ public class CsvLayoutTests : NLogTestBase [Test] public void EndToEndTest() { +#if !NET_CF + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); +#endif + LogManager.Configuration = CreateConfigurationFromString(@" @@ -69,8 +74,8 @@ public void EndToEndTest() "); - - Logger logger = LogManager.GetLogger("A"); + + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); logger.Info("msg2"); logger.Warn("Message with, a comma"); @@ -87,6 +92,9 @@ public void EndToEndTest() [Test] public void NoHeadersTest() { +#if !NET_CF + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); +#endif LogManager.Configuration = CreateConfigurationFromString(@" @@ -103,7 +111,7 @@ public void NoHeadersTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("msg"); logger.Info("msg2"); logger.Warn("Message with, a comma"); diff --git a/tests/NLog.UnitTests/LogManagerTests.cs b/tests/NLog.UnitTests/LogManagerTests.cs index b499afe0..03479c5f 100644 --- a/tests/NLog.UnitTests/LogManagerTests.cs +++ b/tests/NLog.UnitTests/LogManagerTests.cs @@ -56,9 +56,9 @@ public class LogManagerTests : NLogTestBase [Test] public void GetLoggerTest() { - Logger loggerA = LogManager.GetLogger("A"); - Logger loggerA2 = LogManager.GetLogger("A"); - Logger loggerB = LogManager.GetLogger("B"); + ILogger loggerA = LogManager.GetLogger("A"); + ILogger loggerA2 = LogManager.GetLogger("A"); + ILogger loggerB = LogManager.GetLogger("B"); Assert.AreSame(loggerA, loggerA2); Assert.AreNotSame(loggerA, loggerB); Assert.AreEqual("A", loggerA.Name); @@ -69,9 +69,9 @@ public void GetLoggerTest() public void GarbageCollectionTest() { string uniqueLoggerName = Guid.NewGuid().ToString(); - Logger loggerA1 = LogManager.GetLogger(uniqueLoggerName); + ILogger loggerA1 = LogManager.GetLogger(uniqueLoggerName); GC.Collect(); - Logger loggerA2 = LogManager.GetLogger(uniqueLoggerName); + ILogger loggerA2 = LogManager.GetLogger(uniqueLoggerName); Assert.AreSame(loggerA1, loggerA2); } @@ -94,7 +94,7 @@ public void GarbageCollection2Test() [Test] public void NullLoggerTest() { - Logger l = LogManager.CreateNullLogger(); + ILogger l = LogManager.CreateNullLogger(); Assert.AreEqual("", l.Name); } @@ -210,7 +210,7 @@ public void AutoReloadTest() } LogManager.Configuration = new XmlLoggingConfiguration(fileName); AssertDebugCounter("debug", 0); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("aaa"); AssertDebugLastMessage("debug", "aaa"); diff --git a/tests/NLog.UnitTests/LoggerTests.cs b/tests/NLog.UnitTests/LoggerTests.cs index 12b1f798..a269532e 100644 --- a/tests/NLog.UnitTests/LoggerTests.cs +++ b/tests/NLog.UnitTests/LoggerTests.cs @@ -77,7 +77,7 @@ public void TraceTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Trace("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -239,7 +239,7 @@ public void DebugTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -400,7 +400,7 @@ public void InfoTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Info("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -562,7 +562,7 @@ public void WarnTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Warn("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -724,7 +724,7 @@ public void ErrorTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Error("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -883,7 +883,7 @@ public void FatalTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Fatal("message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -1046,7 +1046,7 @@ public void LogTest() "); } - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Log(level, "message"); if (enabled == 1) AssertDebugLastMessage("debug", "message"); @@ -1192,7 +1192,7 @@ public void StringFormatWillNotCauseExceptions() "); - Logger l = LogManager.GetLogger("StringFormatWillNotCauseExceptions"); + ILogger l = LogManager.GetLogger("StringFormatWillNotCauseExceptions"); // invalid format string l.Info("aaaa {0"); diff --git a/tests/NLog.UnitTests/NLogTraceListenerTests.cs b/tests/NLog.UnitTests/NLogTraceListenerTests.cs index e1a1f501..3bab123d 100644 --- a/tests/NLog.UnitTests/NLogTraceListenerTests.cs +++ b/tests/NLog.UnitTests/NLogTraceListenerTests.cs @@ -40,12 +40,14 @@ namespace NLog.UnitTests using System; using System.Diagnostics; using NUnit.Framework; - + using System.Threading; + using System.Globalization; #if !NUNIT using SetUp = Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; using TearDown = Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute; + #endif [TestFixture] @@ -71,6 +73,9 @@ public void TraceWriteTest() Debug.Write("Hello", "Cat1"); AssertDebugLastMessage("debug", "Logger1 Debug Cat1: Hello"); +#if !NET_CF + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); +#endif Debug.Write(3.1415); AssertDebugLastMessage("debug", "Logger1 Debug 3.1415"); @@ -98,6 +103,9 @@ public void TraceWriteLineTest() Debug.WriteLine("Hello", "Cat1"); AssertDebugLastMessage("debug", "Logger1 Debug Cat1: Hello"); +#if !NET_CF + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); +#endif Debug.WriteLine(3.1415); AssertDebugLastMessage("debug", "Logger1 Debug 3.1415"); @@ -193,6 +201,8 @@ public void TraceDataTests() ts.TraceData(TraceEventType.Critical, 123, 42); AssertDebugLastMessage("debug", "MySource1 Fatal 42 123"); + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + ts.TraceData(TraceEventType.Critical, 145, 42, 3.14, "foo"); AssertDebugLastMessage("debug", "MySource1 Fatal 42, 3.14, foo 145"); } diff --git a/tests/NLog.UnitTests/RegressionTests.cs b/tests/NLog.UnitTests/RegressionTests.cs index d9a967a7..0f425f05 100644 --- a/tests/NLog.UnitTests/RegressionTests.cs +++ b/tests/NLog.UnitTests/RegressionTests.cs @@ -82,7 +82,7 @@ public void Bug4655UnableToReconfigureExistingLoggers() SimpleConfigurator.ConfigureForTargetLogging(debugTarget1, LogLevel.Debug); - Logger logger = LogManager.GetLogger(Guid.NewGuid().ToString("N")); + ILogger logger = LogManager.GetLogger(Guid.NewGuid().ToString("N")); logger.Info("foo"); diff --git a/tests/NLog.UnitTests/RoutingTests.cs b/tests/NLog.UnitTests/RoutingTests.cs index 2a22d7c8..e7d1785d 100644 --- a/tests/NLog.UnitTests/RoutingTests.cs +++ b/tests/NLog.UnitTests/RoutingTests.cs @@ -56,7 +56,7 @@ public void LogThresholdTest() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Debug("message"); AssertDebugCounter("debug", 0); @@ -94,7 +94,7 @@ public void LogThresholdTest2() "); - Logger logger = LogManager.GetLogger("A"); + ILogger logger = LogManager.GetLogger("A"); logger.Fatal("messageE"); logger.Error("messageD"); diff --git a/tests/NLog.UnitTests/Targets/ConcurrentFileTargetTests.cs b/tests/NLog.UnitTests/Targets/ConcurrentFileTargetTests.cs index 4fd53297..2745b93f 100644 --- a/tests/NLog.UnitTests/Targets/ConcurrentFileTargetTests.cs +++ b/tests/NLog.UnitTests/Targets/ConcurrentFileTargetTests.cs @@ -56,7 +56,7 @@ namespace NLog.UnitTests.Targets [TestFixture] public class ConcurrentFileTargetTests : NLogTestBase { - private Logger logger = LogManager.GetLogger("NLog.UnitTests.Targets.ConcurrentFileTargetTests"); + private ILogger logger = LogManager.GetLogger("NLog.UnitTests.Targets.ConcurrentFileTargetTests"); private void ConfigureSharedFile(string mode) { diff --git a/tests/NLog.UnitTests/Targets/EventLogTests.cs b/tests/NLog.UnitTests/Targets/EventLogTests.cs index fcb0d809..f30f20eb 100644 --- a/tests/NLog.UnitTests/Targets/EventLogTests.cs +++ b/tests/NLog.UnitTests/Targets/EventLogTests.cs @@ -73,7 +73,7 @@ public void Test1() LogManager.Configuration = null; - Logger l = LogManager.GetCurrentClassLogger(); + ILogger l = LogManager.GetCurrentClassLogger(); l.Info("aaa"); #endif } diff --git a/tests/NLog.UnitTests/Targets/FileTargetTests.cs b/tests/NLog.UnitTests/Targets/FileTargetTests.cs index daab08cb..df0f7648 100644 --- a/tests/NLog.UnitTests/Targets/FileTargetTests.cs +++ b/tests/NLog.UnitTests/Targets/FileTargetTests.cs @@ -63,7 +63,7 @@ namespace NLog.UnitTests.Targets [TestFixture] public class FileTargetTests : NLogTestBase { - private Logger logger = LogManager.GetLogger("NLog.UnitTests.Targets.FileTargetTests"); + private ILogger logger = LogManager.GetLogger("NLog.UnitTests.Targets.FileTargetTests"); [Test] public void SimpleFileTest1() diff --git a/tests/NLog.UnitTests/Targets/RichTextBoxTargetTests.cs b/tests/NLog.UnitTests/Targets/RichTextBoxTargetTests.cs index 5e9c5596..5e414adb 100644 --- a/tests/NLog.UnitTests/Targets/RichTextBoxTargetTests.cs +++ b/tests/NLog.UnitTests/Targets/RichTextBoxTargetTests.cs @@ -60,11 +60,12 @@ namespace NLog.UnitTests.Targets using System.Windows.Forms; using System.Drawing; using NLog.Internal; + using System.Globalization; [TestFixture] public class RichTextBoxTargetTests : NLogTestBase { - private Logger logger = LogManager.GetLogger("NLog.UnitTests.Targets.RichTextBoxTargetTests"); + private ILogger logger = LogManager.GetLogger("NLog.UnitTests.Targets.RichTextBoxTargetTests"); [Test] public void SimpleRichTextBoxTargetTest() @@ -171,7 +172,7 @@ Trace NLog.UnitTests.Targets.RichTextBoxTargetTests Bar\par [Test] public void CustomRowColoringTest() - { + { try { RichTextBoxTarget target = new RichTextBoxTarget() From 5b21ca2ba4af93c1dfc3e44b4b34454e635ece13 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 23 Nov 2011 22:09:07 +0100 Subject: [PATCH 2/4] ILogger does not need the event --- src/NLog/ILogger.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/NLog/ILogger.cs b/src/NLog/ILogger.cs index 9985e47c..1c682a46 100644 --- a/src/NLog/ILogger.cs +++ b/src/NLog/ILogger.cs @@ -41,11 +41,6 @@ namespace NLog /// public interface ILogger { - /// - /// Occurs when logger configuration changes. - /// - event EventHandler LoggerReconfigured; - /// /// Gets the name of the logger. /// From e15583d2626ac5ad9af51973053f63bb8d859ca6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Dec 2011 22:01:10 +0100 Subject: [PATCH 3/4] Added the option archiveAboveSizeUnit to the FileTarget in order to get a better user experience when configuring a filesize. E.g. archiveAboveSize='10' & archiveAboveSizeUnit='KB' will give logfiles with a size of 10 kilobytes. --- src/NLog/NLog.mono2.csproj | 1 + src/NLog/NLog.monodevelop.csproj | 1 + src/NLog/NLog.netcf20.csproj | 1 + src/NLog/NLog.netcf35.csproj | 1 + src/NLog/NLog.netfx20.csproj | 1 + src/NLog/NLog.netfx35.csproj | 1 + src/NLog/NLog.netfx40.csproj | 1 + src/NLog/NLog.sl2.csproj | 1 + src/NLog/NLog.sl3.csproj | 1 + src/NLog/NLog.sl4.csproj | 1 + src/NLog/NLog.wp7.csproj | 1 + src/NLog/NLog.wp71.csproj | 1 + src/NLog/Targets/FileArchiveAboveSizeUnit.cs | 61 +++++++++++++++ src/NLog/Targets/FileTarget.cs | 49 +++++++++++- .../NLog.UnitTests/Targets/FileTargetTests.cs | 78 +++++++++++++++++++ 15 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 src/NLog/Targets/FileArchiveAboveSizeUnit.cs diff --git a/src/NLog/NLog.mono2.csproj b/src/NLog/NLog.mono2.csproj index f78eef73..2b8a1c63 100644 --- a/src/NLog/NLog.mono2.csproj +++ b/src/NLog/NLog.mono2.csproj @@ -314,6 +314,7 @@ + diff --git a/src/NLog/NLog.monodevelop.csproj b/src/NLog/NLog.monodevelop.csproj index caacff7b..748cbfd7 100644 --- a/src/NLog/NLog.monodevelop.csproj +++ b/src/NLog/NLog.monodevelop.csproj @@ -318,6 +318,7 @@ + diff --git a/src/NLog/NLog.netcf20.csproj b/src/NLog/NLog.netcf20.csproj index 2cf04f36..19cecf17 100644 --- a/src/NLog/NLog.netcf20.csproj +++ b/src/NLog/NLog.netcf20.csproj @@ -320,6 +320,7 @@ + diff --git a/src/NLog/NLog.netcf35.csproj b/src/NLog/NLog.netcf35.csproj index c4824d7e..9f90c78a 100644 --- a/src/NLog/NLog.netcf35.csproj +++ b/src/NLog/NLog.netcf35.csproj @@ -321,6 +321,7 @@ + diff --git a/src/NLog/NLog.netfx20.csproj b/src/NLog/NLog.netfx20.csproj index 39e0b260..1b7444cc 100644 --- a/src/NLog/NLog.netfx20.csproj +++ b/src/NLog/NLog.netfx20.csproj @@ -310,6 +310,7 @@ + diff --git a/src/NLog/NLog.netfx35.csproj b/src/NLog/NLog.netfx35.csproj index c4264f35..2f20ded2 100644 --- a/src/NLog/NLog.netfx35.csproj +++ b/src/NLog/NLog.netfx35.csproj @@ -312,6 +312,7 @@ + diff --git a/src/NLog/NLog.netfx40.csproj b/src/NLog/NLog.netfx40.csproj index 67c241f1..6873c904 100644 --- a/src/NLog/NLog.netfx40.csproj +++ b/src/NLog/NLog.netfx40.csproj @@ -318,6 +318,7 @@ + diff --git a/src/NLog/NLog.sl2.csproj b/src/NLog/NLog.sl2.csproj index 0324f200..808d8e1c 100644 --- a/src/NLog/NLog.sl2.csproj +++ b/src/NLog/NLog.sl2.csproj @@ -314,6 +314,7 @@ + diff --git a/src/NLog/NLog.sl3.csproj b/src/NLog/NLog.sl3.csproj index 3ccf175c..916c400f 100644 --- a/src/NLog/NLog.sl3.csproj +++ b/src/NLog/NLog.sl3.csproj @@ -314,6 +314,7 @@ + diff --git a/src/NLog/NLog.sl4.csproj b/src/NLog/NLog.sl4.csproj index 57b84705..e9bd418c 100644 --- a/src/NLog/NLog.sl4.csproj +++ b/src/NLog/NLog.sl4.csproj @@ -315,6 +315,7 @@ + diff --git a/src/NLog/NLog.wp7.csproj b/src/NLog/NLog.wp7.csproj index cbef5768..f9c5783b 100644 --- a/src/NLog/NLog.wp7.csproj +++ b/src/NLog/NLog.wp7.csproj @@ -317,6 +317,7 @@ + diff --git a/src/NLog/NLog.wp71.csproj b/src/NLog/NLog.wp71.csproj index 551588e3..b4a99e06 100644 --- a/src/NLog/NLog.wp71.csproj +++ b/src/NLog/NLog.wp71.csproj @@ -316,6 +316,7 @@ + diff --git a/src/NLog/Targets/FileArchiveAboveSizeUnit.cs b/src/NLog/Targets/FileArchiveAboveSizeUnit.cs new file mode 100644 index 00000000..6677336c --- /dev/null +++ b/src/NLog/Targets/FileArchiveAboveSizeUnit.cs @@ -0,0 +1,61 @@ +// +// Copyright (c) 2004-2011 Jaroslaw Kowalski +// +// 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 +{ + /// + /// Modes of archiving files based on time. + /// + public enum FileArchiveAboveSizeUnit + { + /// + /// Archive based on size specified in bytes + /// + B, + + /// + /// Archive based on size specified in kilobytes + /// + KB, + + /// + /// Archive based on size specified in megabytes + /// + MB, + + /// + /// Archive based on size specified in gigabytes + /// + GB + } +} diff --git a/src/NLog/Targets/FileTarget.cs b/src/NLog/Targets/FileTarget.cs index 3b0f4bd8..3b5ef467 100644 --- a/src/NLog/Targets/FileTarget.cs +++ b/src/NLog/Targets/FileTarget.cs @@ -77,6 +77,7 @@ public FileTarget() this.ConcurrentWriteAttemptDelay = 1; this.ArchiveEvery = FileArchivePeriod.None; this.ArchiveAboveSize = -1; + this.ArchiveAboveSizeUnit = FileArchiveAboveSizeUnit.B; this.ConcurrentWriteAttempts = 10; this.ConcurrentWrites = true; #if SILVERLIGHT @@ -320,6 +321,16 @@ public LineEndingMode LineEnding /// public long ArchiveAboveSize { get; set; } + /// + /// Gets or sets the unit of the size above which log files will be automatically archived. + /// + /// + /// Use this in combination with ArchiveAboveSize. + /// E.g. ArchiveAboveSize=10 and ArchiveAboveSizeUnit=K will give archives of 10240 bytes. + /// + /// + public FileArchiveAboveSizeUnit ArchiveAboveSizeUnit { get; set; } + /// /// Gets or sets a value indicating whether to automatically archive log files every time the specified time passes. /// @@ -362,6 +373,42 @@ public LineEndingMode LineEnding /// public ArchiveNumberingMode ArchiveNumbering { get; set; } + /// + /// Gets the size in bytes above which logfiles are archived + /// + public long ArchiveAboveSizeInBytes + { + get + { + const int RealKilo = 1024; + const long ByteFactor = 1; + const long KilobyteFactor = RealKilo * ByteFactor; + const long MegabyteFactor = RealKilo * KilobyteFactor; + const long GigabyteFactor = RealKilo * MegabyteFactor; + + long factor; + switch (this.ArchiveAboveSizeUnit) + { + case FileArchiveAboveSizeUnit.B: + factor = ByteFactor; + break; + case FileArchiveAboveSizeUnit.KB: + factor = KilobyteFactor; + break; + case FileArchiveAboveSizeUnit.MB: + factor = MegabyteFactor; + break; + case FileArchiveAboveSizeUnit.GB: + factor = GigabyteFactor; + break; + default: + throw new NotSupportedException(string.Format("No known multiply factor for file archive above size unit {0}", this.ArchiveAboveSizeUnit)); + } + + return this.ArchiveAboveSize * factor; + } + } + /// /// Gets the characters that are appended after each line. /// @@ -867,7 +914,7 @@ private bool ShouldAutoArchive(string fileName, LogEventInfo ev, int upcomingWri if (this.ArchiveAboveSize != -1) { - if (fileLength + upcomingWriteSize > this.ArchiveAboveSize) + if (fileLength + upcomingWriteSize > this.ArchiveAboveSizeInBytes) { return true; } diff --git a/tests/NLog.UnitTests/Targets/FileTargetTests.cs b/tests/NLog.UnitTests/Targets/FileTargetTests.cs index df0f7648..33eeb9d8 100644 --- a/tests/NLog.UnitTests/Targets/FileTargetTests.cs +++ b/tests/NLog.UnitTests/Targets/FileTargetTests.cs @@ -264,6 +264,84 @@ public void SequentialArchiveTest1() } } + [Test] + public void SequentialArchiveTest2() + { + // create the file in a not-existent + // directory which forces creation + string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + string tempFile = Path.Combine(tempPath, "file.txt"); + try + { + FileTarget ft = new FileTarget(); + ft.FileName = tempFile; + ft.ArchiveFileName = Path.Combine(tempPath, "archive/{####}.txt"); + ft.ArchiveAboveSize = 1; + ft.ArchiveAboveSizeUnit = FileArchiveAboveSizeUnit.KB; + ft.LineEnding = LineEndingMode.LF; + ft.Layout = "${message}"; + ft.MaxArchiveFiles = 3; + ft.ArchiveNumbering = ArchiveNumberingMode.Sequence; + + SimpleConfigurator.ConfigureForTargetLogging(ft, LogLevel.Debug); + + // we emit 5 * 256 *(3 x aaa + \n) bytes + // so that we should get a full file + 3 archives + for (int i = 0; i < 256; ++i) + { + logger.Debug("aaa"); + } + for (int i = 0; i < 256; ++i) + { + logger.Debug("bbb"); + } + for (int i = 0; i < 256; ++i) + { + logger.Debug("ccc"); + } + for (int i = 0; i < 256; ++i) + { + logger.Debug("ddd"); + } + for (int i = 0; i < 256; ++i) + { + logger.Debug("eee"); + } + + LogManager.Configuration = null; + + AssertFileContents(tempFile, + StringRepeat(256, "eee\n"), + Encoding.UTF8); + + AssertFileContents( + Path.Combine(tempPath, "archive/0001.txt"), + StringRepeat(256, "bbb\n"), + Encoding.UTF8); + + AssertFileContents( + Path.Combine(tempPath, "archive/0002.txt"), + StringRepeat(256, "ccc\n"), + Encoding.UTF8); + + AssertFileContents( + Path.Combine(tempPath, "archive/0003.txt"), + StringRepeat(256, "ddd\n"), + Encoding.UTF8); + + Assert.IsTrue(!File.Exists(Path.Combine(tempPath, "archive/0000.txt"))); + Assert.IsTrue(!File.Exists(Path.Combine(tempPath, "archive/0004.txt"))); + } + finally + { + LogManager.Configuration = null; + if (File.Exists(tempFile)) + File.Delete(tempFile); + if (Directory.Exists(tempPath)) + Directory.Delete(tempPath, true); + } + } + [Test] public void RollingArchiveTest1() { From 6105ee0ba9d3fd16ce3e255200c9c493612ba891 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Dec 2011 20:36:24 +0100 Subject: [PATCH 4/4] Rewrite of FileTarget's archive above size. Because of performance reasons the calculation is only executed when necessary. Added a unit test. --- src/NLog/Targets/FileTarget.cs | 101 ++++++++++++------ .../Config/TargetConfigurationTests.cs | 29 +++++ 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/src/NLog/Targets/FileTarget.cs b/src/NLog/Targets/FileTarget.cs index 3b5ef467..6c8ddcbc 100644 --- a/src/NLog/Targets/FileTarget.cs +++ b/src/NLog/Targets/FileTarget.cs @@ -63,6 +63,8 @@ public class FileTarget : TargetWithLayoutHeaderAndFooter, ICreateFileParameters private BaseFileAppender[] recentAppenders; private Timer autoClosingTimer; private int initializedFilesCounter; + private long archiveAboveSize; + private FileArchiveAboveSizeUnit archiveAboveSizeUnit; /// /// Initializes a new instance of the class. @@ -319,7 +321,19 @@ public LineEndingMode LineEnding /// to false for maximum performance. /// /// - public long ArchiveAboveSize { get; set; } + public long ArchiveAboveSize + { + get + { + return this.archiveAboveSize; + } + + set + { + this.archiveAboveSize = value; + this.CalculateArchiveAboveSizeInBytes(); + } + } /// /// Gets or sets the unit of the size above which log files will be automatically archived. @@ -329,7 +343,19 @@ public LineEndingMode LineEnding /// E.g. ArchiveAboveSize=10 and ArchiveAboveSizeUnit=K will give archives of 10240 bytes. /// /// - public FileArchiveAboveSizeUnit ArchiveAboveSizeUnit { get; set; } + public FileArchiveAboveSizeUnit ArchiveAboveSizeUnit + { + get + { + return this.archiveAboveSizeUnit; + } + + set + { + this.archiveAboveSizeUnit = value; + this.CalculateArchiveAboveSizeInBytes(); + } + } /// /// Gets or sets a value indicating whether to automatically archive log files every time the specified time passes. @@ -378,35 +404,8 @@ public LineEndingMode LineEnding /// public long ArchiveAboveSizeInBytes { - get - { - const int RealKilo = 1024; - const long ByteFactor = 1; - const long KilobyteFactor = RealKilo * ByteFactor; - const long MegabyteFactor = RealKilo * KilobyteFactor; - const long GigabyteFactor = RealKilo * MegabyteFactor; - - long factor; - switch (this.ArchiveAboveSizeUnit) - { - case FileArchiveAboveSizeUnit.B: - factor = ByteFactor; - break; - case FileArchiveAboveSizeUnit.KB: - factor = KilobyteFactor; - break; - case FileArchiveAboveSizeUnit.MB: - factor = MegabyteFactor; - break; - case FileArchiveAboveSizeUnit.GB: - factor = GigabyteFactor; - break; - default: - throw new NotSupportedException(string.Format("No known multiply factor for file archive above size unit {0}", this.ArchiveAboveSizeUnit)); - } - - return this.ArchiveAboveSize * factor; - } + get; + private set; } /// @@ -1227,6 +1226,46 @@ private void InvalidateCacheItem(string fileName) } } } + + private void CalculateArchiveAboveSizeInBytes() + { + long result; + + const int RealKilobyte = 1024; + const long ByteFactor = 1; + const long KilobyteFactor = RealKilobyte * ByteFactor; + const long MegabyteFactor = RealKilobyte * KilobyteFactor; + const long GigabyteFactor = RealKilobyte * MegabyteFactor; + if (this.archiveAboveSizeUnit >= 0) + { + long factor; + switch (this.archiveAboveSizeUnit) + { + case FileArchiveAboveSizeUnit.B: + factor = ByteFactor; + break; + case FileArchiveAboveSizeUnit.KB: + factor = KilobyteFactor; + break; + case FileArchiveAboveSizeUnit.MB: + factor = MegabyteFactor; + break; + case FileArchiveAboveSizeUnit.GB: + factor = GigabyteFactor; + break; + default: + throw new NotSupportedException(string.Format("No known multiply factor for file archive above size unit {0}", this.ArchiveAboveSizeUnit)); + } + + result = this.archiveAboveSize * factor; + } + else + { + result = -1; + } + + this.ArchiveAboveSizeInBytes = result; + } } } diff --git a/tests/NLog.UnitTests/Config/TargetConfigurationTests.cs b/tests/NLog.UnitTests/Config/TargetConfigurationTests.cs index 79fc4292..7ef8baf1 100644 --- a/tests/NLog.UnitTests/Config/TargetConfigurationTests.cs +++ b/tests/NLog.UnitTests/Config/TargetConfigurationTests.cs @@ -97,6 +97,35 @@ public void SimpleElementSyntaxTest() Assert.IsInstanceOfType(typeof(MessageLayoutRenderer), l.Renderers[0]); } + [Test] + public void SimpleElementSyntaxTest2() + { + LoggingConfiguration c = CreateConfigurationFromString(@" + + + + + "); + + FileTarget t = c.FindTargetByName("d") as FileTarget; + Assert.IsNotNull(t); + Assert.AreEqual(t.Name, "d"); + Assert.AreEqual(5L, t.ArchiveAboveSize); + Assert.AreEqual(FileArchiveAboveSizeUnit.MB, t.ArchiveAboveSizeUnit); + Assert.AreEqual(5242880L, t.ArchiveAboveSizeInBytes); + } + [Test] public void ArrayParameterTest() {