# DiagnosticEventCollector

Package: [Microsoft.Orleans.TestingHost](/orleans/docs/api/csharp/microsoft.orleans.testinghost/) 10.0.0

[NuGet package](https://www.nuget.org/packages/Microsoft.Orleans.TestingHost) | [Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.TestingHost/Diagnostics/DiagnosticEventCollector.cs#L26)

```csharp
public sealed class DiagnosticEventCollector : IDisposable, IObserver<KeyValuePair<string, object?>>, IObserver<DiagnosticListener>
```

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

## Remarks

Use this class to wait for specific Orleans events in tests without relying on Task.Delay or Thread.Sleep.

## Constructors

- [DiagnosticEventCollector(IEnumerable&lt;string&gt;)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/constructors/constructor-system-collections-generic-ienumerable-string-nullable-449ce5ea/)
- [DiagnosticEventCollector(string[])](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/constructors/constructor-params-string-array-1-3997af7e/)

## Properties

- [Events](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/properties/events-ff1d8849/)

## Methods

- [Clear](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/clear-0fb6bbf2/)
- [CreateEventAwaiter(string)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/createeventawaiter-string-04631d49/)
- [Dispose](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/dispose-c728a1e6/)
- [GetEventCount(string)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/geteventcount-string-0a3e9953/)
- [GetEvents(string)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/getevents-string-56da67c0/)
- [WaitForEventAsync(string, Func&lt;DiagnosticEvent, bool&gt;, TimeSpan, CancellationToken)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventasync-string-system-func-orleans-testinghost-diagnostics-diagnostice-33aae6e6/)
- [WaitForEventAsync(string, TimeSpan, CancellationToken)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventasync-string-system-timespan-system-threading-cancellationtoken-9fec3d4c/)
- [WaitForEventCountAsync(string, int, TimeSpan, CancellationToken)](/orleans/docs/api/csharp/microsoft.orleans.testinghost/orleans.testinghost.diagnostics.diagnosticeventcollector/methods/waitforeventcountasync-string-int-system-timespan-system-threading-cancellationt-d1ab0d10/)
