Skip to content

Commit

Permalink
Merge pull request #1919 from NLog/internallogger-lamba
Browse files Browse the repository at this point in the history
Func overloads for InternalLogger
  • Loading branch information
304NotModified committed Jan 21, 2017
2 parents 3e87ca7 + d26e278 commit 56bf853
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 16 deletions.
132 changes: 132 additions & 0 deletions src/NLog/Common/InternalLogger-generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ public static void Trace([Localizable(false)] string message)
Write(null, LogLevel.Trace, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Trace.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Trace([Localizable(false)] Func<string> messageFunc)
{
if (IsTraceEnabled)
Write(null, LogLevel.Trace, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Trace level.
Expand Down Expand Up @@ -175,6 +185,18 @@ public static void Trace<TArgument1>([Localizable(false)] string message, TArgum
public static void Trace(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Trace, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Trace level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Trace.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Trace(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsTraceEnabled)
Write(ex, LogLevel.Trace, messageFunc(), null);
}

/// <summary>
Expand All @@ -197,6 +219,16 @@ public static void Debug([Localizable(false)] string message)
Write(null, LogLevel.Debug, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Debug level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Debug.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Debug([Localizable(false)] Func<string> messageFunc)
{
if (IsDebugEnabled)
Write(null, LogLevel.Debug, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Debug level.
Expand Down Expand Up @@ -263,6 +295,18 @@ public static void Debug<TArgument1>([Localizable(false)] string message, TArgum
public static void Debug(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Debug, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Debug level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Debug.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Debug(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsDebugEnabled)
Write(ex, LogLevel.Debug, messageFunc(), null);
}

/// <summary>
Expand All @@ -285,6 +329,16 @@ public static void Info([Localizable(false)] string message)
Write(null, LogLevel.Info, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Info level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Info.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Info([Localizable(false)] Func<string> messageFunc)
{
if (IsInfoEnabled)
Write(null, LogLevel.Info, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Info level.
Expand Down Expand Up @@ -351,6 +405,18 @@ public static void Info<TArgument1>([Localizable(false)] string message, TArgume
public static void Info(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Info, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Info level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Info.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Info(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsInfoEnabled)
Write(ex, LogLevel.Info, messageFunc(), null);
}

/// <summary>
Expand All @@ -373,6 +439,16 @@ public static void Warn([Localizable(false)] string message)
Write(null, LogLevel.Warn, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Warn level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Warn.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Warn([Localizable(false)] Func<string> messageFunc)
{
if (IsWarnEnabled)
Write(null, LogLevel.Warn, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Warn level.
Expand Down Expand Up @@ -439,6 +515,18 @@ public static void Warn<TArgument1>([Localizable(false)] string message, TArgume
public static void Warn(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Warn, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Warn level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Warn.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Warn(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsWarnEnabled)
Write(ex, LogLevel.Warn, messageFunc(), null);
}

/// <summary>
Expand All @@ -461,6 +549,16 @@ public static void Error([Localizable(false)] string message)
Write(null, LogLevel.Error, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Error level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Error.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Error([Localizable(false)] Func<string> messageFunc)
{
if (IsErrorEnabled)
Write(null, LogLevel.Error, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Error level.
Expand Down Expand Up @@ -527,6 +625,18 @@ public static void Error<TArgument1>([Localizable(false)] string message, TArgum
public static void Error(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Error, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Error level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Error.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Error(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsErrorEnabled)
Write(ex, LogLevel.Error, messageFunc(), null);
}

/// <summary>
Expand All @@ -549,6 +659,16 @@ public static void Fatal([Localizable(false)] string message)
Write(null, LogLevel.Fatal, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Fatal level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Fatal.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Fatal([Localizable(false)] Func<string> messageFunc)
{
if (IsFatalEnabled)
Write(null, LogLevel.Fatal, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Fatal level.
Expand Down Expand Up @@ -615,6 +735,18 @@ public static void Fatal<TArgument1>([Localizable(false)] string message, TArgum
public static void Fatal(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.Fatal, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Fatal level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level Fatal.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Fatal(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (IsFatalEnabled)
Write(ex, LogLevel.Fatal, messageFunc(), null);
}

}
Expand Down
32 changes: 31 additions & 1 deletion src/NLog/Common/InternalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ public static void Log(LogLevel level, [Localizable(false)] string message)
Write(null, level, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the specified level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level <paramref name="level"/>.
/// </summary>
/// <param name="level">Log level.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void Log(LogLevel level, [Localizable(false)] Func<string> messageFunc)
{
if (level >= LogLevel)
{
Write(null, level, messageFunc(), null);
}
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the specified level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level <paramref name="level"/>.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="level">Log level.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
[StringFormatMethod("message")]
public static void Log(Exception ex, LogLevel level, [Localizable(false)] Func<string> messageFunc)
{
if (level >= LogLevel)
{
Write(ex, level, messageFunc(), null);
}
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the specified level.
/// </summary>
Expand Down Expand Up @@ -343,7 +373,7 @@ private static void WriteToTrace(string message)
{
return;
}

System.Diagnostics.Trace.WriteLine(message, "NLog");
}

Expand Down
22 changes: 22 additions & 0 deletions src/NLog/Common/InternalLogger.tt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ namespace NLog.Common
Write(null, LogLevel.<#=level#>, message, null);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the <#=level#> level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level <#=level#>.
/// </summary>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void <#=level#>([Localizable(false)] Func<string> messageFunc)
{
if (Is<#=level#>Enabled)
Write(null, LogLevel.<#=level#>, messageFunc(), null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the <#=level#> level.
Expand Down Expand Up @@ -146,6 +156,18 @@ namespace NLog.Common
public static void <#=level#>(Exception ex, [Localizable(false)] string message)
{
Write(ex, LogLevel.<#=level#>, message, null);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the <#=level#> level.
/// <paramref name="messageFunc"/> will be only called when logging is enabled for level <#=level#>.
/// </summary>
/// <param name="ex">Exception to be logged.</param>
/// <param name="messageFunc">Function that returns the log message.</param>
public static void <#=level#>(Exception ex, [Localizable(false)] Func<string> messageFunc)
{
if (Is<#=level#>Enabled)
Write(ex, LogLevel.<#=level#>, messageFunc(), null);
}
<#
}
Expand Down
Loading

0 comments on commit 56bf853

Please sign in to comment.