<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.0-preview.1.22076.8" />

ActivitySource

public sealed class ActivitySource : IDisposable
Provides APIs to create and start Activity objects and to register ActivityListener objects to listen to the Activity events.
public string Name { get; }

Returns the activity source name.

public string Version { get; }

Returns the activity source version.

public ActivitySource(string name, string version = "")

Constructs an activity source object with the specified name.

public static void AddActivityListener(ActivityListener listener)

Adds a listener to the activity starting and stopping events.

public Activity CreateActivity(string name, ActivityKind kind)

Creates a new Activity object if there is any listener to the Activity, returns null otherwise.

public Activity CreateActivity(string name, ActivityKind kind, ActivityContext parentContext, IEnumerable<KeyValuePair<string, object>> tags = null, IEnumerable<ActivityLink> links = null, ActivityIdFormat idFormat = 0)

Creates a new Activity object if there is any listener to the Activity, returns null otherwise. If the Activity object is created, it will not automatically start. Callers will need to call Start to start it.

public Activity CreateActivity(string name, ActivityKind kind, string parentId, IEnumerable<KeyValuePair<string, object>> tags = null, IEnumerable<ActivityLink> links = null, ActivityIdFormat idFormat = 0)

Creates a new Activity object if there is any listener to the Activity, returns null otherwise.

public void Dispose()

Disposes the activity source object, removes the current instance from the global list, and empties the listeners list.

public bool HasListeners()

Checks if there are any listeners for this activity source.

public Activity StartActivity(string name = "", ActivityKind kind = 0)

Creates a new activity if there are active listeners for it, using the specified name and activity kind.

public Activity StartActivity(string name, ActivityKind kind, ActivityContext parentContext, IEnumerable<KeyValuePair<string, object>> tags = null, IEnumerable<ActivityLink> links = null, DateTimeOffset startTime = default)

Creates a new activity if there are active listeners for it, using the specified name, activity kind, parent activity context, tags, optional activity link and optional start time.

public Activity StartActivity(string name, ActivityKind kind, string parentId, IEnumerable<KeyValuePair<string, object>> tags = null, IEnumerable<ActivityLink> links = null, DateTimeOffset startTime = default)

Creates a new activity if there are active listeners for it, using the specified name, activity kind, parent Id, tags, optional activity links and optional start time.

public Activity StartActivity(ActivityKind kind, ActivityContext parentContext = default, IEnumerable<KeyValuePair<string, object>> tags = null, IEnumerable<ActivityLink> links = null, DateTimeOffset startTime = default, string name = "")

Creates and starts a new Activity object if there is any listener to the Activity events, returns null otherwise.