Степан Степан - 1 year ago 170
C# Question

NLog global properties

Using NLog is there any way to define global

properties for logs?
Using construction

var logEventInfo = new LogEventInfo(LogLevel.Trace, Log.Name, "Hello world");
logEventInfo.Properties["messageName"] = "MessageName2";

isn't suitable, because in big project everywhere using
and similar methods. But we need to add some parameters to watch them at
logging without rewriting code.

Answer Source

Are you looking for the global diagnostic context / mapped diagnostic context?

Set in your code:

GlobalDiagnosticsContext.Set("prop1", "I'm scoped for all threads");
MappedDiagnosticsContext.Set("prop2", "I'm scoped per thread and child thread");

Usage in config:


See also https://github.com/nlog/nlog/wiki/gdc-Layout-Renderer & https://github.com/nlog/nlog/wiki/mdc-Layout-Renderer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download