Ejemplo n.º 1
0
        public void Test_Telemetry_LogErrorExceptionWithObject()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Error);

                // Act
                logger.LogError(new Exception("test"), new Test
                {
                    PropA = "propA",
                    PropB = 1,
                    PropC = true,
                    PropD = new SubItem
                    {
                        PropE = "propE",
                        PropF = new List <int> {
                            1, 2, 3
                        }
                    }
                });
                logger.Flush();
            });
        }
Ejemplo n.º 2
0
        public void Test_Telemetry_IsEnabled()
        {
            // Arrange
            var logger = new AppInsightsLogger("test", LogLevel.Trace);

            logger.BeginScope("test");
            logger.Flush();

            // Act/Assert
            Assert.True(logger.IsEnabled(LogLevel.Information));
        }
Ejemplo n.º 3
0
        public void Test_Telemetry_LogLevelInfoWithEvent()
        {
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Information);

                // Act
                logger.Log(LogLevel.Information, new EventId(1, "test"), "test", null, null);
                logger.Flush();
            });
        }
Ejemplo n.º 4
0
        public void Test_Telemetry_LogCriticalMessage()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogCritical("test");
                logger.Flush();
            });
        }
Ejemplo n.º 5
0
        public void Test_Telemetry_LogWithWrongLevel()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Warning);

                // Act
                logger.LogDebug("test");
                logger.Flush();
            });
        }
Ejemplo n.º 6
0
        public void Test_Telemetry_LogLevelNoneWithException()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.None);

                // Act
                logger.Log(LogLevel.Trace, new EventId(1, "test"), "test", new Exception(), null);
                logger.Flush();
            });
        }
Ejemplo n.º 7
0
        public void Test_Telemetry_LogExceptionWithMessage()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogError(new Exception(), "Some error");
                logger.Flush();
            });
        }
Ejemplo n.º 8
0
        public void Test_Telemetry_LogWarningException()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogWarning(new Exception());
                logger.Flush();
            });
        }
Ejemplo n.º 9
0
        public void Test_Telemetry_LogMetricWithProperties()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogMetric("test", 3.1, new Dictionary <string, string> {
                    { "a", "a" }, { "b", "b" }
                });
                logger.Flush();
            });
        }
Ejemplo n.º 10
0
        public void Test_Telemetry_ExceptionWithDictionary()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogError(new Exception(), new Dictionary <string, string> {
                    { "a", "a" }
                });
                logger.Flush();
            });
        }
Ejemplo n.º 11
0
        public void Test_Telemetry_LogExceptionWithMessageAndProperties()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogError(new Exception(), "Some error", new Dictionary <string, string>()
                {
                    { "test", "test" }
                });
                logger.Flush();
            });
        }
Ejemplo n.º 12
0
        public void Test_Telemetry_LogInformationMessage()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);
                Dictionary <string, string> statistics = new Dictionary <string, string>()
                {
                    { "SomeProp1", "sample1" },
                    { "SomeProp2", "sample2" },
                    { "SomeProp3", "sample3" }
                };

                logger.LogInformation("test title", statistics);
                logger.Log(LogLevel.Information, new EventId(1, null), "A", null, (a, b) =>
                {
                    return(string.Format("{0}:{1}", a, b));
                });
                logger.Flush();
            });
        }