Skip to content

Commit

Permalink
Fixes empty "properties" collection.
Browse files Browse the repository at this point in the history
When using an event-context variable, the properties collection was
empty, even when property items where explicitly given. This function
fixes this.
  • Loading branch information
erwinwolff committed May 1, 2014
1 parent 3f21263 commit acb1636
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/NLog/Targets/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ protected virtual void Write(LogEventInfo logEvent)
protected virtual void Write(AsyncLogEventInfo logEvent)
{
try
{
{
this.MergeEventProperties(logEvent.LogEvent);

this.Write(logEvent.LogEvent);
logEvent.Continuation(null);
}
Expand Down Expand Up @@ -472,6 +474,22 @@ private void GetAllLayouts()
{
this.allLayouts = new List<Layout>(ObjectGraphScanner.FindReachableObjects<Layout>(this));
InternalLogger.Trace("{0} has {1} layouts", this, this.allLayouts.Count);
}

private void MergeEventProperties(LogEventInfo logEvent)
{
foreach (var item in logEvent.Parameters)
{
if (item.GetType() == typeof(LogEventInfo))

This comment has been minimized.

Copy link
@cvanbergen

cvanbergen Jun 13, 2014

Contributor

On line 483, item can be null. This will throw a System.NullReferenceException causing the entire logEvent NOT to be logged.

{

foreach (var propertyItem in ((LogEventInfo)item).Properties)
{
logEvent.Properties.Remove(propertyItem.Key);
logEvent.Properties.Add(propertyItem);
}
}
}
}
}
}

0 comments on commit acb1636

Please sign in to comment.