Skip to content

NLog target does not capture Properties #56

@JonCubed

Description

@JonCubed

NLog has Event Properties which is used for logging custom values.

LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, "", "Pass my custom value");
theEvent.Properties.Add("MyValue", "My custom string");
theEvent.Properties.Add("MyDateTimeValue", new DateTime(2015, 08, 30, 11, 26, 50));
logger.Log(theEvent);

Currently the NLog target does not capture these values and it would be very nice if it could.

a naive fix would be adding something like below

if (loggingEvent.Properties.Any())
{
    // capture properties of log event
   loggingEvent
         .Properties
         .ToList()
         .ForEach(prop => diags.Add(prop.Key.ToString(), prop.Value));
 }

after

var diags = GetDiagnosticContextProperties();
if (diags != null && diags.ContainsKey("transid"))
{
msg.TransID = diags["transid"].ToString();
diags.Remove("transid");
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions