public void DoesNotReportEventsBeforeActivation() { var healthReporterMock = new Mock <IHealthReporter>(); var observer = new Mock <IObserver <EventData> >(); var inputConfiguration = new List <EtwProviderConfiguration>(); inputConfiguration.Add(new EtwProviderConfiguration { ProviderName = TestTraceEventSession.TestEtwProviderName }); using (var input = new EtwInput(inputConfiguration, healthReporterMock.Object)) using (input.Subscribe(observer.Object)) { var traceSession = new TestTraceEventSession(); input.SessionFactory = () => traceSession; traceSession.ReportEvent(LogLevel.Informational, 0, "First"); input.Activate(); traceSession.ProcessingStarted.WaitOne(TraceSessionActivationTimeout); traceSession.ReportEvent(LogLevel.Informational, 0, "Second"); observer.Verify(o => o.OnNext(It.IsAny <EventData>()), Times.Exactly(1)); observer.Verify(o => o.OnNext(It.Is <EventData>(data => data.Payload["Message"].Equals("Second") && data.Level == LogLevel.Informational ))); VerifyNoErrorsOrWarnings(healthReporterMock); } }
public async Task ReportsClrEvents() { var healthReporterMock = new Mock <IHealthReporter>(); var observer = new TestObserver(); var inputConfiguration = new List <EtwProviderConfiguration>(); inputConfiguration.Add(new EtwProviderConfiguration { // For more info about this provider configuration see https://docs.microsoft.com/en-us/dotnet/framework/performance/exception-thrown-v1-etw-event // and https://docs.microsoft.com/en-us/dotnet/framework/performance/clr-etw-events ProviderGuid = new Guid("e13c0d23-ccbc-4e12-931b-d9cc2eee27e4"), Level = TraceEventLevel.Warning, Keywords = (TraceEventKeyword)0x8000 }); using (var input = new EtwInput(inputConfiguration, healthReporterMock.Object)) using (input.Subscribe(observer)) { input.Activate(); // Activation of the input causes creation of an ETW listening session in a separate Task. // It takes a bit of time for the session to start capturing events. // Use a small delay to minimize the chance that the following exception will be missed. await Task.Delay(TimeSpan.FromMilliseconds(500)); try { throw new Exception("We seek perfection"); } catch (Exception) { } EventData exceptionEvent = null; bool exceptionEventRaised = await TaskUtils.PollWaitAsync(() => { var fetched = observer.Data.TryDequeue(out exceptionEvent); if (!fetched) { return(false); } return(exceptionEvent.Payload.Keys.Contains("ExceptionMessage") && string.Equals("We seek perfection", exceptionEvent.Payload["ExceptionMessage"])); }, TimeSpan.FromSeconds(5)); Assert.True(exceptionEventRaised); VerifyNoErrorsOrWarnings(healthReporterMock); } }