-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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.
${scopeindent:indent=Layout}
-
indent - Delimiter to insert for every nested state level in ScopeContext.
Layout
. Default
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();
}
}
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json