EventSource.SetCurrentThreadActivityId Method

Definition

Sets the activity ID on the current thread.

Overloads

SetCurrentThreadActivityId(Guid)

Sets the activity ID on the current thread.

SetCurrentThreadActivityId(Guid, Guid)

Sets the activity ID on the current thread, and returns the previous activity ID.

SetCurrentThreadActivityId(Guid)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Sets the activity ID on the current thread.

C#
public static void SetCurrentThreadActivityId(Guid activityId);

Parameters

activityId
Guid

The current thread's new activity ID, or Empty to indicate that work on the current thread is not associated with any activity.

Remarks

Calling the SetCurrentThreadActivityId method sets the activity ID on a per-thread basis. All events on the thread will have that activity ID until a new activity is started on the same thread.

This method is called only by libraries that manage their own threads.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

SetCurrentThreadActivityId(Guid, Guid)

Source:
EventSource.cs
Source:
EventSource.cs
Source:
EventSource.cs

Sets the activity ID on the current thread, and returns the previous activity ID.

C#
public static void SetCurrentThreadActivityId(Guid activityId, out Guid oldActivityThatWillContinue);

Parameters

activityId
Guid

The current thread's new activity ID, or Empty to indicate that work on the current thread is not associated with any activity.

oldActivityThatWillContinue
Guid

When this method returns, contains the previous activity ID on the current thread.

Remarks

You can call the SetCurrentThreadActivityId(Guid, Guid) method to temporarily overwrite the current thread's activity ID with a new activity ID. You must then restore the previous activity ID by passing the oldActivityThatWillContinue argument to the SetCurrentThreadActivityId(Guid) method.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0