Beispiel #1
0
        public void TestLoggerWithNegativeFilterDoesNotCreateTraceTelemetryOnLoggedInfo()
        {
            bool            trackedTelemetry = false;
            TelemetryClient client           = CommonMocks.MockTelemetryClient((t) => trackedTelemetry = true);

            ILogger logger = new ApplicationInsightsLogger("test-category", client, (s, l) => { return(false); }, defaultOptions);

            logger.LogInformation(0, "This is an information");

            Assert.False(trackedTelemetry);
        }
Beispiel #2
0
        public void TestLoggerCreatesTraceTelemetryOnLoggedInfo()
        {
            TelemetryClient client = CommonMocks.MockTelemetryClient((t) =>
            {
                Assert.IsType <TraceTelemetry>(t);
                var traceTelemetry = (TraceTelemetry)t;
                Assert.Equal("This is an information", traceTelemetry.Message);
                Assert.Equal(SeverityLevel.Information, traceTelemetry.SeverityLevel);
                Assert.Equal("test-category", traceTelemetry.Properties["CategoryName"]);
            });

            ILogger logger = new ApplicationInsightsLogger("test-category", client, (s, l) => { return(true); }, null);

            logger.LogInformation(0, "This is an information");
        }
Beispiel #3
0
        public void TestLoggerIncludingEventIdCreatesTraceTelemetryWithoutEventNameOnLoggedInfo()
        {
            TelemetryClient client = CommonMocks.MockTelemetryClient((t) =>
            {
                Assert.IsType <TraceTelemetry>(t);
                var traceTelemetry = (TraceTelemetry)t;
                Assert.Equal("This is an information", traceTelemetry.Message);
                Assert.Equal(SeverityLevel.Information, traceTelemetry.SeverityLevel);
                Assert.Equal("test-category", traceTelemetry.Properties["CategoryName"]);

                Assert.Equal("100", traceTelemetry.Properties["EventId"]);
                Assert.False(traceTelemetry.Properties.ContainsKey("EventName"));
            });
            var options = new ApplicationInsightsLoggerOptions {
                IncludeEventId = true
            };

            ILogger logger = new ApplicationInsightsLogger("test-category", client, (s, l) => { return(true); }, options);

            logger.LogInformation(new EventId(100, string.Empty), "This is an information");
        }