-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Event Context Layout Renderer
Rolf Kristensen edited this page Dec 8, 2022
·
7 revisions
Log event property data.
Platforms Supported: All
${event-properties:item=MyValue}
Note that ${event-properties} syntax replaces the now deprecated ${event-context}
syntax.
- item - Name of the item (required)
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"
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json