Skip to content

Commit

Permalink
Merge pull request #697 from Xharze/v3.2.1-manual
Browse files Browse the repository at this point in the history
V3.2.1 manual merge
  • Loading branch information
kichristensen committed May 10, 2015
2 parents dd34806 + ffd15f3 commit 3944557
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 127 deletions.
14 changes: 14 additions & 0 deletions src/NLog/Config/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ public LoggingConfiguration()
this.LoggingRules = new List<LoggingRule>();
}

/// <summary>
/// Gets the variables defined in the configuration.
/// </summary>
/// <remarks>
/// Returns null if not configured using XML configuration.
/// </remarks>
public virtual Dictionary<string, string> Variables
{
get
{
throw new NotSupportedException("Variables is only supported in XmlConfiguration");
}
}

/// <summary>
/// Gets a collection of named targets specified in the configuration.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Config/XmlLoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static LoggingConfiguration AppConfig
/// <summary>
/// Gets the variables defined in the configuration.
/// </summary>
public Dictionary<string, string> Variables
public override Dictionary<string, string> Variables
{
get
{
Expand Down
112 changes: 56 additions & 56 deletions src/NLog/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ namespace NLog
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Linq;
using Internal.Fakeables;
using NLog.Common;
Expand Down Expand Up @@ -181,7 +181,7 @@ public static void AddHiddenAssembly(Assembly assembly)
lock (lockObject)
{
if (_hiddenAssemblies != null && _hiddenAssemblies.Contains(assembly))
return;
return;

_hiddenAssemblies = new HashSet<Assembly>(_hiddenAssemblies ?? Enumerable.Empty<Assembly>())
{
Expand Down Expand Up @@ -256,23 +256,23 @@ public static void Flush()
factory.Flush();
}

/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="timeout">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(TimeSpan timeout)
{
factory.Flush(timeout);
}
/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="timeout">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(TimeSpan timeout)
{
factory.Flush(timeout);
}

/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="timeoutMilliseconds">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(int timeoutMilliseconds)
{
factory.Flush(timeoutMilliseconds);
}
/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="timeoutMilliseconds">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(int timeoutMilliseconds)
{
factory.Flush(timeoutMilliseconds);
}
#endif

/// <summary>
Expand All @@ -284,25 +284,25 @@ public static void Flush(AsyncContinuation asyncContinuation)
factory.Flush(asyncContinuation);
}

/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="asyncContinuation">The asynchronous continuation.</param>
/// <param name="timeout">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(AsyncContinuation asyncContinuation, TimeSpan timeout)
{
factory.Flush(asyncContinuation, timeout);
}
/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="asyncContinuation">The asynchronous continuation.</param>
/// <param name="timeout">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(AsyncContinuation asyncContinuation, TimeSpan timeout)
{
factory.Flush(asyncContinuation, timeout);
}

/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="asyncContinuation">The asynchronous continuation.</param>
/// <param name="timeoutMilliseconds">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(AsyncContinuation asyncContinuation, int timeoutMilliseconds)
{
factory.Flush(asyncContinuation, timeoutMilliseconds);
}
/// <summary>
/// Flush any pending log messages (in case of asynchronous targets).
/// </summary>
/// <param name="asyncContinuation">The asynchronous continuation.</param>
/// <param name="timeoutMilliseconds">Maximum time to allow for the flush. Any messages after that time will be discarded.</param>
public static void Flush(AsyncContinuation asyncContinuation, int timeoutMilliseconds)
{
factory.Flush(asyncContinuation, timeoutMilliseconds);
}

/// <summary>
/// Decreases the log enable counter and if it reaches -1 the logs are disabled.
Expand Down Expand Up @@ -349,6 +349,25 @@ public static void Shutdown()
}
}

#if !SILVERLIGHT && !MONO
private static void SetupTerminationEvents()
{
try
{
CurrentAppDomain.ProcessExit += TurnOffLogging;
CurrentAppDomain.DomainUnload += TurnOffLogging;
}
catch (Exception exception)
{
if (exception.MustBeRethrown())
{
throw;
}

InternalLogger.Warn("Error setting up termination events: {0}", exception);
}
}

/// <summary>
/// Gets the fully qualified name of the class invoking the LogManager, including the
/// namespace but not the assembly.
Expand Down Expand Up @@ -381,25 +400,6 @@ private static string GetClassFullName()
return className;
}

#if !SILVERLIGHT && !MONO
private static void SetupTerminationEvents()
{
try
{
CurrentAppDomain.ProcessExit += TurnOffLogging;
CurrentAppDomain.DomainUnload += TurnOffLogging;
}
catch (Exception exception)
{
if (exception.MustBeRethrown())
{
throw;
}

InternalLogger.Warn("Error setting up termination events: {0}", exception);
}
}

private static void TurnOffLogging(object sender, EventArgs args)
{
// Reset logging configuration to null; this causes old configuration (if any) to be
Expand Down
75 changes: 37 additions & 38 deletions src/NLog/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ protected internal Logger()
/// </summary>
public LogFactory Factory { get; private set; }


/// <summary>
/// Gets a value indicating whether logging is enabled for the specified level.
/// </summary>
Expand Down Expand Up @@ -193,10 +192,10 @@ public void LogException(LogLevel level, [Localizable(false)] string message, Ex
/// <param name="args">Arguments to format.</param>
[StringFormatMethod("message")]
public void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args)
{
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, formatProvider, message, args);
this.WriteToTargets(level, formatProvider, message, args);
}
}

Expand All @@ -205,8 +204,8 @@ public void Log(LogLevel level, IFormatProvider formatProvider, [Localizable(fal
/// </summary>
/// <param name="level">The log level.</param>
/// <param name="message">Log message.</param>
public void Log(LogLevel level, [Localizable(false)] string message)
{
public void Log(LogLevel level, [Localizable(false)] string message)
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, null, message);
Expand All @@ -219,8 +218,8 @@ public void Log(LogLevel level, [Localizable(false)] string message)
/// <param name="level">The log level.</param>
/// <param name="message">A <see langword="string" /> containing format items.</param>
/// <param name="args">Arguments to format.</param>
public void Log(LogLevel level, [Localizable(false)] string message, params object[] args)
{
public void Log(LogLevel level, [Localizable(false)] string message, params object[] args)
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, message, args);
Expand Down Expand Up @@ -283,10 +282,10 @@ public void Log(LogLevel level, Exception exception, IFormatProvider formatProvi
/// <param name="argument">The argument to format.</param>
[StringFormatMethod("message")]
public void Log<TArgument>(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument argument)
{
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, formatProvider, message, new object[] { argument });
this.WriteToTargets(level, formatProvider, message, new object[] { argument });
}
}

Expand Down Expand Up @@ -316,11 +315,11 @@ public void Log<TArgument>(LogLevel level, [Localizable(false)] string message,
/// <param name="message">A <see langword="string" /> containing one format item.</param>
/// <param name="argument1">The first argument to format.</param>
/// <param name="argument2">The second argument to format.</param>
public void Log<TArgument1, TArgument2>(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2)
{
public void Log<TArgument1, TArgument2>(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2)
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, formatProvider, message, new object[] { argument1, argument2 });
this.WriteToTargets(level, formatProvider, message, new object[] { argument1, argument2 });
}
}

Expand All @@ -335,7 +334,7 @@ public void Log<TArgument>(LogLevel level, [Localizable(false)] string message,
/// <param name="argument2">The second argument to format.</param>
[StringFormatMethod("message")]
public void Log<TArgument1, TArgument2>(LogLevel level, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2)
{
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, message, new object[] { argument1, argument2 });
Expand All @@ -354,11 +353,11 @@ public void Log<TArgument>(LogLevel level, [Localizable(false)] string message,
/// <param name="argument1">The first argument to format.</param>
/// <param name="argument2">The second argument to format.</param>
/// <param name="argument3">The third argument to format.</param>
public void Log<TArgument1, TArgument2, TArgument3>(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3)
{
public void Log<TArgument1, TArgument2, TArgument3>(LogLevel level, IFormatProvider formatProvider, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3)
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, formatProvider, message, new object[] { argument1, argument2, argument3 });
this.WriteToTargets(level, formatProvider, message, new object[] { argument1, argument2, argument3 });
}
}

Expand All @@ -375,13 +374,34 @@ public void Log<TArgument>(LogLevel level, [Localizable(false)] string message,
/// <param name="argument3">The third argument to format.</param>
[StringFormatMethod("message")]
public void Log<TArgument1, TArgument2, TArgument3>(LogLevel level, [Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3)
{
{
if (this.IsEnabled(level))
{
this.WriteToTargets(level, message, new object[] { argument1, argument2, argument3 });
}
}

internal void WriteToTargets(LogLevel level, Exception ex, [Localizable(false)] string message, object[] args)
{
LoggerImpl.Write(this.loggerType, this.GetTargetsForLevel(level), PrepareLogEventInfo(LogEventInfo.Create(level, this.Name, ex, this.Factory.DefaultCultureInfo, message, args)), this.Factory);
}

internal void WriteToTargets(LogLevel level, Exception ex, IFormatProvider formatProvider, [Localizable(false)] string message, object[] args)
{
LoggerImpl.Write(this.loggerType, this.GetTargetsForLevel(level), PrepareLogEventInfo(LogEventInfo.Create(level, this.Name, ex, formatProvider, message, args)), this.Factory);
}


private LogEventInfo PrepareLogEventInfo(LogEventInfo logEvent)
{
if (logEvent.FormatProvider == null)
{
logEvent.FormatProvider = this.Factory.DefaultCultureInfo;
}
return logEvent;

}

#endregion


Expand Down Expand Up @@ -516,16 +536,6 @@ internal void WriteToTargets(LogLevel level, [Localizable(false)] string message
LoggerImpl.Write(this.loggerType, this.GetTargetsForLevel(level), PrepareLogEventInfo(LogEventInfo.Create(level, this.Name, message, ex)), this.Factory);
}

internal void WriteToTargets(LogLevel level, Exception ex, [Localizable(false)] string message, object[] args)
{
LoggerImpl.Write(this.loggerType, this.GetTargetsForLevel(level), PrepareLogEventInfo(LogEventInfo.Create(level, this.Name, ex, this.Factory.DefaultCultureInfo, message, args)), this.Factory);
}

internal void WriteToTargets(LogLevel level, Exception ex, IFormatProvider formatProvider, [Localizable(false)] string message, object[] args)
{
LoggerImpl.Write(this.loggerType, this.GetTargetsForLevel(level), PrepareLogEventInfo(LogEventInfo.Create(level, this.Name, ex, formatProvider, message, args)), this.Factory);
}


internal void WriteToTargets(LogLevel level, [Localizable(false)] string message, object[] args)
{
Expand All @@ -542,17 +552,6 @@ internal void WriteToTargets(Type wrapperType, LogEventInfo logEvent)
LoggerImpl.Write(wrapperType ?? this.loggerType, this.GetTargetsForLevel(logEvent.Level), PrepareLogEventInfo(logEvent), this.Factory);
}


private LogEventInfo PrepareLogEventInfo(LogEventInfo logEvent)
{
if (logEvent.FormatProvider == null)
{
logEvent.FormatProvider = this.Factory.DefaultCultureInfo;
}
return logEvent;

}

internal void SetConfiguration(LoggerConfiguration newConfiguration)
{
this.configuration = newConfiguration;
Expand Down
Loading

0 comments on commit 3944557

Please sign in to comment.