Skip to content

Trace Activity Id Layout Renderer

Rolf Kristensen edited this page Jul 2, 2025 · 20 revisions

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.

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