<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.2" />

ActivityListener

public sealed class ActivityListener : IDisposable
ActivityListener allows listening to the start and stop Activity events and give the oppertunity to decide creating the Activity for sampling scenarios.
public Action<Activity> ActivityStarted { get; set; }

Set or get the callback used to listen to the Activity start event.

public Action<Activity> ActivityStopped { get; set; }

Set or get the callback used to listen to the Activity stop event.

public SampleActivity<ActivityContext> Sample { get; set; }

Set or get the callback used to decide allowing creating Activity objects with specific data state.

public SampleActivity<string> SampleUsingParentId { get; set; }

Set or get the callback used to decide allowing creating Activity objects with specific data state.

public Func<ActivitySource, bool> ShouldListenTo { get; set; }

Set or get the callback used to decide if want to listen to Activity objects events which created using ActivitySource object.

Construct a new ActivityListener object to start listening to the Activity events.

public void Dispose()

Dispose will unregister this ActivityListener object from listening to Activity events.