Skip to content

DiagnosticEventCollector Methods

A test utility for collecting and waiting on diagnostic events. Subscribes to System.Diagnostics.DiagnosticListener.AllListeners and captures events from listeners matching specified patterns.

CreateEventAwaiter(string)

View source
public TaskCompletionSource<DiagnosticEvent> CreateEventAwaiter(string eventName)
Creates a task that completes when the specified event is captured. Unlike WaitForEventAsync, this does not check for existing events.

Parameters

eventNamestring
The name of the event to wait for.

Returns

A task completion source that will be completed when the event is captured.

Dispose

View source
public void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetEvents(string)

View source
public IEnumerable<DiagnosticEvent> GetEvents(string eventName)
Gets events with the specified name.

Parameters

eventNamestring

WaitForEventAsync(string, Func<DiagnosticEvent, bool>, TimeSpan, CancellationToken)

View source
public Task<DiagnosticEvent> WaitForEventAsync(string eventName, Func<DiagnosticEvent, bool> predicate, TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
Waits for an event with the specified name that matches a predicate.

Parameters

eventNamestring
The name of the event to wait for.
predicateFunc<DiagnosticEvent, bool>
A predicate to match the event payload.
timeoutTimeSpan
The maximum time to wait.
cancellationTokenCancellationToken
A cancellation token.

Returns

The captured event.

WaitForEventAsync(string, TimeSpan, CancellationToken)

View source
public Task<DiagnosticEvent> WaitForEventAsync(string eventName, TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
Waits for an event with the specified name to be captured. If an event with that name has already been captured, returns immediately.

Parameters

eventNamestring
The name of the event to wait for.
timeoutTimeSpan
The maximum time to wait.
cancellationTokenCancellationToken
A cancellation token.

Returns

The captured event.

Exceptions

System.TimeoutException
Thrown if the event is not captured within the timeout.

WaitForEventCountAsync(string, int, TimeSpan, CancellationToken)

View source
public Task<IReadOnlyList<DiagnosticEvent>> WaitForEventCountAsync(string eventName, int expectedCount, TimeSpan timeout, CancellationToken cancellationToken = default(CancellationToken))
Waits until at least the specified number of events with the given name have been captured.

Parameters

eventNamestring
The name of the event to count.
expectedCountint
The minimum number of events expected.
timeoutTimeSpan
The maximum time to wait.
cancellationTokenCancellationToken
A cancellation token.

Returns

All captured events with the specified name.

Exceptions

System.TimeoutException
Thrown if the expected count is not reached within the timeout.