Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: InternalLogger should only allocate params-array when needed #1702

Merged
merged 2 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions src/NLog/Common/InternalLogger-generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,45 @@ public static void Trace(Exception ex, [Localizable(false)] string message, para
Write(ex, LogLevel.Trace, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Trace([Localizable(false)] string message, object arg0)
{
if (IsTraceEnabled)
Log(null, LogLevel.Trace, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Trace([Localizable(false)] string message, object arg0, object arg1)
{
if (IsTraceEnabled)
Log(null, LogLevel.Trace, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Trace([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsTraceEnabled)
Log(null, LogLevel.Trace, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Trace level.
/// </summary>
Expand Down Expand Up @@ -165,6 +204,45 @@ public static void Debug(Exception ex, [Localizable(false)] string message, para
Write(ex, LogLevel.Debug, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Debug([Localizable(false)] string message, object arg0)
{
if (IsDebugEnabled)
Log(null, LogLevel.Debug, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Debug([Localizable(false)] string message, object arg0, object arg1)
{
if (IsDebugEnabled)
Log(null, LogLevel.Debug, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Debug([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsDebugEnabled)
Log(null, LogLevel.Debug, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Debug level.
/// </summary>
Expand Down Expand Up @@ -208,6 +286,45 @@ public static void Info(Exception ex, [Localizable(false)] string message, param
Write(ex, LogLevel.Info, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Info([Localizable(false)] string message, object arg0)
{
if (IsInfoEnabled)
Log(null, LogLevel.Info, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Info([Localizable(false)] string message, object arg0, object arg1)
{
if (IsInfoEnabled)
Log(null, LogLevel.Info, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Info([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsInfoEnabled)
Log(null, LogLevel.Info, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Info level.
/// </summary>
Expand Down Expand Up @@ -251,6 +368,45 @@ public static void Warn(Exception ex, [Localizable(false)] string message, param
Write(ex, LogLevel.Warn, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Warn([Localizable(false)] string message, object arg0)
{
if (IsWarnEnabled)
Log(null, LogLevel.Warn, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Warn([Localizable(false)] string message, object arg0, object arg1)
{
if (IsWarnEnabled)
Log(null, LogLevel.Warn, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Warn([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsWarnEnabled)
Log(null, LogLevel.Warn, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Warn level.
/// </summary>
Expand Down Expand Up @@ -294,6 +450,45 @@ public static void Error(Exception ex, [Localizable(false)] string message, para
Write(ex, LogLevel.Error, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Error([Localizable(false)] string message, object arg0)
{
if (IsErrorEnabled)
Log(null, LogLevel.Error, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Error([Localizable(false)] string message, object arg0, object arg1)
{
if (IsErrorEnabled)
Log(null, LogLevel.Error, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Error([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsErrorEnabled)
Log(null, LogLevel.Error, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Error level.
/// </summary>
Expand Down Expand Up @@ -337,6 +532,45 @@ public static void Fatal(Exception ex, [Localizable(false)] string message, para
Write(ex, LogLevel.Fatal, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void Fatal([Localizable(false)] string message, object arg0)
{
if (IsFatalEnabled)
Log(null, LogLevel.Fatal, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void Fatal([Localizable(false)] string message, object arg0, object arg1)
{
if (IsFatalEnabled)
Log(null, LogLevel.Fatal, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void Fatal([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (IsFatalEnabled)
Log(null, LogLevel.Fatal, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the Fatal level.
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions src/NLog/Common/InternalLogger.tt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ namespace NLog.Common
Write(ex, LogLevel.<#=level#>, message, args);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
[StringFormatMethod("message")]
public static void <#=level#>([Localizable(false)] string message, object arg0)
{
if (Is<#=level#>Enabled)
Log(null, LogLevel.<#=level#>, message, arg0);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
[StringFormatMethod("message")]
public static void <#=level#>([Localizable(false)] string message, object arg0, object arg1)
{
if (Is<#=level#>Enabled)
Log(null, LogLevel.<#=level#>, message, arg0, arg1);
}

/// <summary>
/// Logs the specified message without an <see cref="Exception"/> at the Trace level.
/// </summary>
/// <param name="message">Message which may include positional parameters.</param>
/// <param name="arg0">Argument {0} to the message.</param>
/// <param name="arg1">Argument {1} to the message.</param>
/// <param name="arg2">Argument {2} to the message.</param>
[StringFormatMethod("message")]
public static void <#=level#>([Localizable(false)] string message, object arg0, object arg1, object arg2)
{
if (Is<#=level#>Enabled)
Log(null, LogLevel.<#=level#>, message, arg0, arg1, arg2);
}

/// <summary>
/// Logs the specified message with an <see cref="Exception"/> at the <#=level#> level.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Internal/FileAppenders/BaseFileAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected FileStream CreateFileStream(bool allowFileSharedWriting)
{
int currentDelay = this.CreateFileParameters.ConcurrentWriteAttemptDelay;

InternalLogger.Trace("Opening {0} with allowFileSharedWriting={1}", this.FileName, allowFileSharedWriting);
InternalLogger.Trace("Opening {0} with allowFileSharedWriting={1}", this.FileName, allowFileSharedWriting.ToString(System.Globalization.CultureInfo.InvariantCulture));
for (int i = 0; i < this.CreateFileParameters.ConcurrentWriteAttempts; ++i)
{
try
Expand Down
7 changes: 3 additions & 4 deletions src/NLog/Targets/Wrappers/AsyncTargetWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ protected virtual void StartLazyWriterTimer()
{
if (this.TimeToSleepBetweenBatches <= 0)
{
if (InternalLogger.IsTraceEnabled)
InternalLogger.Trace("AsyncWrapper '{0}': Throttled timer scheduled", Name);
InternalLogger.Trace("AsyncWrapper '{0}': Throttled timer scheduled", this.Name);
this.lazyWriterTimer.Change(1, Timeout.Infinite);
}
else
Expand Down Expand Up @@ -331,7 +330,7 @@ private void ProcessPendingEvents(object state)

if (this.WrappedTarget == null)
{
InternalLogger.Error("AsyncWrapper '{0}': WrappedTarget is NULL", Name);
InternalLogger.Error("AsyncWrapper '{0}': WrappedTarget is NULL", this.Name);
return;
}

Expand All @@ -352,7 +351,7 @@ private void ProcessPendingEvents(object state)
wroteFullBatchSize = true;

if (InternalLogger.IsTraceEnabled || continuation != null)
InternalLogger.Trace("AsyncWrapper '{0}': Flushing {1} events.", Name, logEventInfos.Length);
InternalLogger.Trace("AsyncWrapper '{0}': Flushing {1} events.", this.Name, logEventInfos.Length);

if (continuation != null)
{
Expand Down
Loading