# DiagnosticEventCollector Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/)

## Clear {#clear-0fb6bbf2}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/clear-0fb6bbf2/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L84-L85)

```csharp
public void Clear()
```

Clears all captured events.

## CreateEventAwaiter(string) {#createeventawaiter-string-04631d49}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/createeventawaiter-string-04631d49/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L168)

```csharp
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

- `eventName` (`string`): The name of the event to wait for.

### Returns

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

## Dispose {#dispose-c728a1e6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/dispose-c728a1e6/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L311-L320)

```csharp
public void Dispose()
```

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

## GetEventCount(string) {#geteventcount-string-0a3e9953}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/geteventcount-string-0a3e9953/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L77)

```csharp
public int GetEventCount(string eventName)
```

Gets the count of events with the specified name.

### Parameters

- `eventName` (`string`)

## GetEvents(string) {#getevents-string-56da67c0}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/getevents-string-56da67c0/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L71)

```csharp
public IEnumerable<DiagnosticEvent> GetEvents(string eventName)
```

Gets events with the specified name.

### Parameters

- `eventName` (`string`)

## WaitForEventAsync(string, Func&lt;DiagnosticEvent, bool&gt;, TimeSpan, CancellationToken) {#waitforeventasync-string-system-func-orleans-testinghost-diagnostics-diagnostice-33aae6e6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventasync-string-system-func-orleans-testinghost-diagnostics-diagnostice-33aae6e6/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs)

```csharp
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

- `eventName` (`string`): The name of the event to wait for.
- `predicate` (`Func<DiagnosticEvent, bool>`): A predicate to match the event payload.
- `timeout` (`TimeSpan`): The maximum time to wait.
- `cancellationToken` (`CancellationToken`): A cancellation token.

### Returns

The captured event.

## WaitForEventAsync(string, TimeSpan, CancellationToken) {#waitforeventasync-string-system-timespan-system-threading-cancellationtoken-9fec3d4c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventasync-string-system-timespan-system-threading-cancellationtoken-9fec3d4c/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs)

```csharp
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

- `eventName` (`string`): The name of the event to wait for.
- `timeout` (`TimeSpan`): The maximum time to wait.
- `cancellationToken` (`CancellationToken`): 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) {#waitforeventcountasync-string-int-system-timespan-system-threading-cancellationt-d1ab0d10}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventcountasync-string-int-system-timespan-system-threading-cancellationt-d1ab0d10/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L186-L223)

```csharp
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

- `eventName` (`string`): The name of the event to count.
- `expectedCount` (`int`): The minimum number of events expected.
- `timeout` (`TimeSpan`): The maximum time to wait.
- `cancellationToken` (`CancellationToken`): 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.
