-
Notifications
You must be signed in to change notification settings - Fork 1.4k
NDLC Layout Renderer
Rolf Kristensen edited this page Aug 29, 2023
·
22 revisions
⚠️ NLog 5.0 introduces ScopeContext that replaces NDLC + NDC
Nested Diagnostics Logical Context (NDLC) acts like a stack of string, that are stored in an Async-Local structure (Similar to "Thread Context" in Log4j). It is the async version of NDC Layout Renderer
Platforms Supported: All
Introduced in NLog 4.4.1
It enables one to assign a scope-name to the active scope (Ex. a request method-name). Then all logger-events created within the scoped logical context, can automatically capture the scope-name without needing to specify it with each LogEvent. The specified scope states will automatically flow together with async Tasks.
See also NLog Context.
${ndlc:bottomFrames=Integer:topFrames=Integer:separator=String}
-
bottomFrames - Number of bottom stack frames to be rendered.
-1
is no limit.Integer
. Default-1
. -
topFrames - Number of top stack frames to be rendered.
-1
is no limit.Integer
. Default-1
-
separator - Separator to be used for concatenating nested diagnostics context output.
string
. Default
using (NLog.NestedDiagnosticsLogicalContext.Push("Outer Scope"))
{
Logger.Info("Hello Outer");
await InnerOperationAsync();
}
static async Task InnerOperationAsync()
{
using (NLog.NestedDiagnosticsLogicalContext.Push("Inner Scope"))
{
Logger.Info("Hello Inner");
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
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json