Ads by Lake Quincy Media

Wiki Navigation

 
Gibraltar - Learn about the best analysis tool for NLog

Event-context layout renderer

NLog documentation is a Wiki, which allows registered users to edit its content.
If you want to contribute, please create a user account and contact Jarek to get edit access.

Log event context data. 

Supported in

Configuration Syntax

${event-context:item=String}
Read more about using the Configuration File.

Parameters

  • Rendering Options
  • item - Name of the item. Required.

Example

In C# class, create an event and add an element to the Properties dictionary (or the deprecated Context dictionary):

...
Logger log = LogManager.GetCurrentClassLogger();
LogEventInfo theEvent = new LogEventInfo(LogLevel.Debug, "", "Pass my custom value");
theEvent.Properties["MyValue"] = "My custom string";
// deprecated
theEvent.Context["TheAnswer"] = 42;
log.Log(theEvent);
...

and in your NLog.config file:

${event-context:item=MyValue} -- renders "My custom string"
${event-context:item=TheAnswer} -- renders "42"