Skip to content

ScopeIndent Layout Renderer

Rolf Kristensen edited this page Oct 25, 2022 · 1 revision

ScopeContext Nested States are stored in the thread execution context. Similar to "Nested Diagnostic Context" (NDC) in Log4j.

Platforms Supported: All (AsyncLocal is used for NetStandard and Net46, but older platforms uses Remoting.Messaging.CallContext)

Introduced with NLog 5.0.5

Inserts indent-delimiter for every nested state in the ScopeContext.

Configuration Syntax

${scopeindent:indent=Layout}

Parameters

  • indent - Delimiter to insert for every nested state level in ScopeContext. Layout. Default (double space)

Examples

Logger.Info("Hello No Scope");              // Will not be indented

using (NLog.ScopeContext.PushNestedState("First Scope"))
{
   Logger.Info("Hello First Scope");        // Will be indented once
   await InnerOperationAsync();
}

static async Task InnerOperationAsync()
{
    using (NLog.ScopeContext.PushNestedState("Second Scope"))
    {
        Logger.Info("Hello Second Scope");   // Will be indented twice
        await Task.Yield();
    }
}
Clone this wiki locally