Skip to content

MDLC Layout Renderer

Rolf Kristensen edited this page Apr 21, 2019 · 15 revisions

Use the Mapped Diagnostic Logical Context when you have information that you want available to every logger executing on the current logical context (Similar to "Thread Context Map" in Log4j)

Platforms Supported: Limited (Not supported on Silverlight).

Introduced with NLog 4.1 (NLog 4.1.1 add support for any Object type, not just String)

Mapped Diagnostic Logical Context is the async version of the Mapped Diagnostics Context - a logical call context structure that keeps a dictionary of strings and provides methods to output them in layouts. Allows for maintaining state across asynchronous tasks and call contexts.

See also LogEvent Context Information.

Configuration Syntax



Rendering Options

  • item - Name of the item. Required.


Simple Properties

The following example demonstrates the basic usage of the Mapped Diagnostic Logical Context.

MappedDiagnosticsLogicalContext.Set("PropertyName", "PropertyValue");
MappedDiagnosticsLogicalContext.Set("PropertyName2", "AnotherPropertyValue");

Add the following to your logger configuration to reference the above properties.


Scoped item

The SetScoped method returns an IDisposable that removes the added item when disposed. It can be used in conjunction with the using statement to limit the scope during which the item will be present in the context.

using (MappedDiagnosticsLogicalContext.SetScoped("Property", "PropertyValue")) {
    // "Property" item is present in current context
// "Property" item has been removed from current context
Clone this wiki locally
You can’t perform that action at this time.