コード例 #1
0
 public void InitializeFailedWhenSourceIsNotSpecified()
 {
     using (EventSourceModuleDiagnosticListener listener = new EventSourceModuleDiagnosticListener())
         using (TraceEventSessionMock traceEventSession = new TraceEventSessionMock(false))
             using (EtwTelemetryModule module = new EtwTelemetryModule(() => traceEventSession))
             {
                 module.Initialize(GetTestTelemetryConfiguration());
                 Assert.AreEqual(1, listener.EventsReceived.Count);
                 Assert.AreEqual(NoEventSourcesConfiguredEventId, listener.EventsReceived[0].EventId);
                 Assert.AreEqual("EtwTelemetryModule", listener.EventsReceived[0].Payload[1].ToString());
             }
 }
コード例 #2
0
 public void InitializeSucceed()
 {
     using (EventSourceModuleDiagnosticListener listener = new EventSourceModuleDiagnosticListener())
         using (TraceEventSessionMock traceEventSession = new TraceEventSessionMock(false))
             using (EtwTelemetryModule module = new EtwTelemetryModule(() => traceEventSession))
             {
                 module.Sources.Add(new EtwListeningRequest()
                 {
                     ProviderName = "Test Provider",
                     Level        = Diagnostics.Tracing.TraceEventLevel.Always
                 });
                 module.Initialize(GetTestTelemetryConfiguration());
                 Assert.AreEqual(0, listener.EventsReceived.Count);
             }
 }
コード例 #3
0
 public void ProviderNotEnabledByEmptyGuid()
 {
     using (EventSourceModuleDiagnosticListener listener = new EventSourceModuleDiagnosticListener())
         using (TraceEventSessionMock traceEventSession = new TraceEventSessionMock(false))
             using (EtwTelemetryModule module = new EtwTelemetryModule(() => traceEventSession))
             {
                 Guid guid = Guid.Empty;
                 module.Sources.Add(new EtwListeningRequest()
                 {
                     ProviderGuid = guid,
                     Level        = Diagnostics.Tracing.TraceEventLevel.Always
                 });
                 module.Initialize(GetTestTelemetryConfiguration());
                 Assert.IsFalse(traceEventSession.EnabledProviderGuids.Any(g => Guid.Empty.Equals(g)));
             }
 }
コード例 #4
0
 public void ProviderEnabledByGuid()
 {
     using (EventSourceModuleDiagnosticListener listener = new EventSourceModuleDiagnosticListener())
         using (TraceEventSessionMock traceEventSession = new TraceEventSessionMock(false))
             using (EtwTelemetryModule module = new EtwTelemetryModule(() => traceEventSession))
             {
                 Guid guid = Guid.NewGuid();
                 module.Sources.Add(new EtwListeningRequest()
                 {
                     ProviderGuid = guid,
                     Level        = Diagnostics.Tracing.TraceEventLevel.Always
                 });
                 module.Initialize(GetTestTelemetryConfiguration());
                 Assert.AreEqual(2, traceEventSession.EnabledProviderGuids.Count);
                 // First enabled provider is the TPL provider
                 Assert.AreEqual(guid.ToString(), traceEventSession.EnabledProviderGuids[1].ToString());
             }
 }
コード例 #5
0
 public void InitializeFailedWhenAccessDenied()
 {
     using (EventSourceModuleDiagnosticListener listener = new EventSourceModuleDiagnosticListener())
         using (TraceEventSessionMock traceEventSession = new TraceEventSessionMock(true))
             using (EtwTelemetryModule module = new EtwTelemetryModule(() => traceEventSession))
             {
                 module.Sources.Add(new EtwListeningRequest()
                 {
                     ProviderName = "Test Provider",
                     Level        = Diagnostics.Tracing.TraceEventLevel.Always
                 });
                 module.Initialize(GetTestTelemetryConfiguration());
                 // There will be 2 events because we also enable TPL EventSource to get hierarchical activity IDs.
                 Assert.AreEqual(2, listener.EventsReceived.Count);
                 Assert.AreEqual(AccessDeniedEventId, listener.EventsReceived[0].EventId);
                 Assert.AreEqual("Access Denied.", listener.EventsReceived[0].Payload[1].ToString());
             }
 }