Skip to content

Trace Activity Id Layout Renderer

Rolf Kristensen edited this page Jan 12, 2023 · 18 revisions

Outputs the Trace.CorrelationManager.ActivityId as trace correlation id.

Platforms Supported: Limited (Not supported NetStandard1.3+1.5)

Introduced in NLog v4.1.

Configuration Syntax

${activityid}

Remarks

⚠️ Trace.CorrelationManager.ActivityId is now considered legacy and replaced by System.Diagnostics.Activity.Current. 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.

Example

For an ASP.Net WebAPI application, initialize the Trace.CorrelationManager.ActivityId in the Global.asax, Application_BeginRequest event:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    ...
    Trace.CorrelationManager.ActivityId = Guid.NewGuid();
}
Clone this wiki locally