public void ReportsSeverityLevel() { using (var module = new EventSourceTelemetryModule()) { var listeningRequest = new EventSourceListeningRequest(); listeningRequest.Name = TestEventSource.ProviderName; module.Sources.Add(listeningRequest); module.Initialize(GetTestTelemetryConfiguration()); TestEventSource.Default.InfoEvent("Hey!"); TestEventSource.Default.WarningEvent(1, 2); TestEventSource.Default.ErrorEvent(2.3, "default context"); TraceTelemetry[] expectedTelemetry = new TraceTelemetry[] { new TraceTelemetry("Hey!", SeverityLevel.Information), new TraceTelemetry("Warning!", SeverityLevel.Warning), new TraceTelemetry("Error!", SeverityLevel.Error) }; CollectionAssert.AreEqual(expectedTelemetry, this.adapterHelper.Channel.SentItems, new TraceTelemetryComparer(), "Reported events are not what was expected"); } }
public void PrefixMatchEnablingEventSource() { using (var module = new EventSourceTelemetryModule()) { var listeningRequest = new EventSourceListeningRequest() { Name = TestEventSource.ProviderName.Substring(0, TestEventSource.ProviderName.Length - 2), PrefixMatch = true }; module.Sources.Add(listeningRequest); module.Initialize(GetTestTelemetryConfiguration()); TestEventSource.Default.InfoEvent("Hey!"); TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.Single(); Assert.AreEqual("Hey!", telemetry.Message); Assert.AreEqual("Hey!", telemetry.Properties["information"]); Assert.AreEqual(SeverityLevel.Information, telemetry.SeverityLevel); string expectedVersion = SdkVersionHelper.GetExpectedSdkVersion(prefix: "evl:", loggerType: typeof(EventSourceTelemetryModule)); Assert.AreEqual(expectedVersion, telemetry.Context.GetInternalContext().SdkVersion); } }
public void DisablingEventFromEventSource() { using (var module = new EventSourceTelemetryModule()) { var listeningRequest = new EventSourceListeningRequest() { Name = TestEventSource.ProviderName }; module.Sources.Add(listeningRequest); var disablingRequest = new DisableEventSourceRequest() { Name = TestEventSource.ProviderName }; module.DisabledSources.Add(disablingRequest); module.Initialize(GetTestTelemetryConfiguration()); TestEventSource.Default.InfoEvent("Hey!"); int sentCount = this.adapterHelper.Channel.SentItems.Count(); Assert.AreEqual(0, sentCount); } }