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 1, 2018
1 parent 728870a commit 005df7a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/NLog.Extensions.Logging/Logging/NLogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ public void Log<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId
eventInfo.Exception = exception;
}

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

CaptureEventId(eventInfo, eventId);
Expand All @@ -90,14 +87,18 @@ private LogEventInfo CreateLogEventInfo(LogLevel nLogLogLevel, string message, I
{
// Parsing failed or no messageParameters
var eventInfo = LogEventInfo.Create(nLogLogLevel, _logger.Name, message);
if (messageParameters?.Count > 0)
if (messageParameters != null)
{
for (int i = 0; i < messageParameters.Count; ++i)
{
var property = messageParameters[i];
eventInfo.Properties[property.Name] = property.Value;
}
}
else if (messageProperties != null && _options.CaptureMessageProperties)
{
CaptureMessagePropertiesList(eventInfo, messageProperties);
}
return eventInfo;
}
}
Expand Down

0 comments on commit 005df7a

Please sign in to comment.