Skip to content

Event Context Layout Renderer

Rolf Kristensen edited this page Dec 8, 2022 · 7 revisions

Log event property data.

Platforms Supported: All

Configuration Syntax

${event-properties:item=MyValue}

Note that ${event-properties} syntax replaces the now deprecated ${event-context} syntax.

Parameters

Rendering Options

  • item - Name of the item (required)

Example

In your C# code, 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-properties:item=MyValue}   -- renders "My custom string"
${event-properties:item=TheAnswer} -- renders "42"
Clone this wiki locally