<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0-preview.2.23128.3" />

ActivitySource

public sealed class ActivitySource : IDisposable
public string Name { get; }

Returns the ActivitySource name.

public string Version { get; }

Returns the ActivitySource version.

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

Construct an ActivitySource object with the input name

public static void AddActivityListener(ActivityListener listener)

Add 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()

Dispose the ActivitySource object and remove the current instance from the global list. empty the listeners list too.

public bool HasListeners()

Check if there is any listeners for this ActivitySource. This property can be helpful to tell if there is no listener, then no need to create Activity object and avoid creating the objects needed to create Activity (e.g. ActivityContext) Example of that is http scenario which can avoid reading the context data from the wire.

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

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

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

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

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

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

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.