-
Notifications
You must be signed in to change notification settings - Fork 1.4k
NDC Layout Renderer
Rolf Kristensen edited this page Aug 29, 2023
·
16 revisions
⚠️ NLog 5.0 introduces ScopeContext that replaces NDLC + NDC
Nested Diagnostics Context - a thread-local structure that keeps a stack of strings and provides methods to output them in layouts.
Platforms Supported: All
NDC is considered legacy, and instead is recommended to use NDLC that includes support for async Tasks. See also NLog Context
${ndc: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
NestedDiagnosticsContext.Push("entering method X");
... // log here
NestedDiagnosticsContext.Pop(); //leaving methods
Then in the log config:
${ndc}
logs entering method X
if logged between push()
and pop()
NestedDiagnosticsContext.Push("entering method X1");
NestedDiagnosticsContext.Push("entering method X2");
... // log here
NestedDiagnosticsContext.Pop(); //leaving method X2
NestedDiagnosticsContext.Pop(); //leaving method X1
logs entering method X1 entering method X2
- 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