Skip to content

Trace Activity Id Layout Renderer

Rolf Kristensen edited this page May 31, 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 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.

Example

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.

Clone this wiki locally