Skip to content

Commit

Permalink
NLogLogger - Move some complexity out of Log-method
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Aug 2, 2018
1 parent 25b231d commit b86da07
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/NLog.Extensions.Logging/Logging/NLogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId

CaptureEventId(eventInfo, eventId);

if (exception != null)
{
eventInfo.Exception = exception;
}

_logger.Log(typeof(Microsoft.Extensions.Logging.ILogger), eventInfo);
}

Expand All @@ -59,25 +64,24 @@ private LogEventInfo CreateLogEventInfo<TState>(LogLevel nLogLogLevel, TState st
? NLogMessageParameterList.TryParse(messageProperties)
: null;

string formattedMesage = null;
LogEventInfo eventInfo =
TryParseMessageTemplate(nLogLogLevel, messageProperties, messageParameters) ??
TryCaptureMessageTemplate(nLogLogLevel, formattedMesage ?? (formattedMesage = formatter(state, exception)), messageProperties, messageParameters) ??
CreateSimpleLogEventInfo(nLogLogLevel, formattedMesage, messageProperties, messageParameters);
CreateLogEventInfo(nLogLogLevel, formatter(state, exception), messageProperties, messageParameters);

if (messageParameters == null && messageProperties == null && _options.CaptureMessageProperties)
{
CaptureMessageProperties(eventInfo, state);
}

if (exception != null)
{
eventInfo.Exception = exception;
}

return eventInfo;
}

private LogEventInfo CreateLogEventInfo(LogLevel nLogLogLevel, string formattedMessage, IReadOnlyList<KeyValuePair<string, object>> messageProperties, NLogMessageParameterList messageParameters)
{
return TryCaptureMessageTemplate(nLogLogLevel, formattedMessage, messageProperties, messageParameters) ??
CreateSimpleLogEventInfo(nLogLogLevel, formattedMessage, messageProperties, messageParameters);
}

/// <summary>
/// Checks if the already parsed input message-parameters must be sent through
/// the NLog MessageTemplate Parser for proper handling of message-template syntax.
Expand Down

0 comments on commit b86da07

Please sign in to comment.