Skip to content

Commit

Permalink
MessageTemplate - Capture structured logging parameter names (Better …
Browse files Browse the repository at this point in the history
…option name)
  • Loading branch information
snakefoot committed Oct 14, 2017
1 parent 348c975 commit f4bf50d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/NLog.Extensions.Logging/NLogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId
}
var message = formatter(state, exception);

var messageTemplate = _options.EnableStructuredLogging ? state as IReadOnlyList<KeyValuePair<string, object>> : null;
var messageTemplate = _options.CaptureMessageTemplates ? state as IReadOnlyList<KeyValuePair<string, object>> : null;
LogEventInfo eventInfo = CreateLogEventInfo(nLogLogLevel, message, messageTemplate);
eventInfo.Exception = exception;
if (!_options.IgnoreEmptyEventId || eventId.Id != 0 || !string.IsNullOrEmpty(eventId.Name))
Expand Down
4 changes: 2 additions & 2 deletions src/NLog.Extensions.Logging/NLogProviderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class NLogProviderOptions
public bool IgnoreEmptyEventId { get; set; }

/// <summary>
/// Attempt to capture parameter names and values and insert into <see cref="LogEventInfo.Properties" />-dictionary
/// Enable structured logging by capturing message template parameters and inject into the <see cref="LogEventInfo.Properties" />-dictionary
/// </summary>
public bool EnableStructuredLogging { get; set; }
public bool CaptureMessageTemplates { get; set; }

/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
public NLogProviderOptions()
Expand Down
2 changes: 1 addition & 1 deletion test/LoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static IServiceProvider BuildDi()
var serviceProvider = services.BuildServiceProvider();
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();

loggerFactory.AddNLog(new NLogProviderOptions() { EnableStructuredLogging = true });
loggerFactory.AddNLog(new NLogProviderOptions() { CaptureMessageTemplates = true });
loggerFactory.ConfigureNLog("nlog.config");
return serviceProvider;
}
Expand Down

0 comments on commit f4bf50d

Please sign in to comment.