-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Trace Activity Id Layout Renderer
Outputs the Trace.CorrelationManager.ActivityId as trace correlation id.
Platforms Supported: All - Requires nuget-package NLog.Targets.Trace since NLog v6
Introduced in NLog v4.1.
${activityid}
⚠️ Trace.CorrelationManager.ActivityId is now considered legacy and instead replaced by System.Diagnostics.Activity. See also: ${activity}
If the Trace.CorrelationManager.ActivityId is equal to Guid.Empty, then appends String.Empty, otherwise appends Trace.CorrelationManager.ActivityId as separated by hyphens according to the CultureInfo.InvariantCulture.
For an ASP.NET IIS application, initialize the Trace.CorrelationManager.ActivityId in the Global.asax.cs, Application_BeginRequest event:
protected void Application_BeginRequest(object sender, EventArgs e)
{
...
if (Trace.CorrelationManager.ActivityId == Guid.Empty)
{
Trace.CorrelationManager.ActivityId = Guid.NewGuid();
}
}Notice IIS Express might automatically setup ActivityId without needing the above code.
- 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