Skip to content

Commit

Permalink
Altered null check
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanbergen committed Jun 17, 2014
1 parent ceb1e58 commit 02e7eff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/NLog/Targets/Target.cs
Expand Up @@ -485,13 +485,13 @@ private void MergeEventProperties(LogEventInfo logEvent)

foreach (var item in logEvent.Parameters)
{
if (item!=null && item.GetType() == typeof(LogEventInfo))
var logEventParameter = item as LogEventInfo;
if (logEventParameter != null)
{

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

1 comment on commit 02e7eff

@oakio
Copy link

@oakio oakio commented on 02e7eff Aug 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error occured:
System.InvalidOperationException was caught
HResult=-2146233079
Message=Collection was modified; enumeration operation may not execute.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at NLog.Targets.Target.MergeEventProperties(LogEventInfo logEvent) in c:\Projects\NLog\src\NLog\Targets\Target.cs:line 496
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent) in c:\Projects\NLog\src\NLog\Targets\Target.cs:line 438
InnerException:

You should write:

logEvent.Properties[propertyItem.Key] = propertyItem.Value;

instead:

logEventParameter.Properties.Remove(propertyItem.Key);
logEventParameter.Properties.Add(propertyItem);

Please sign in to comment.