Beispiel #1
0
        public void DefaultFilterCheck()
        {
            var configSection = LoggerConfigSectionSetup("DefaultFilterCheck.json", null).GetSection("LogLevel");

            if (!(configSection != null && configSection.GetChildren().Count() > 0))
            {
                configSection = null;
            }
            var categoryName = "AWS.Log";
            var coreLogger   = new FakeCoreLogger();
            var logger       = new AWSLogger(
                categoryName,
                coreLogger,
                AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName));

            logger.LogTrace("trace");
            logger.LogDebug("debug");
            logger.LogInformation("information");
            logger.LogWarning("warning");
            logger.LogError("error");
            logger.LogCritical("critical");

            Assert.Equal(5, coreLogger.ReceivedMessages.Count);
            Assert.True(coreLogger.ReceivedMessages.Contains("warning"));
            Assert.True(coreLogger.ReceivedMessages.Contains("error"));
            Assert.True(coreLogger.ReceivedMessages.Contains("critical"));
        }
        public void ValidAppsettingsFilter()
        {
            var configSection = LoggerConfigSectionSetup("ValidAppsettingsFilter.json", null).GetSection("LogLevel");

            if (!(configSection != null && configSection.GetChildren().Count() > 0))
            {
                configSection = null;
            }
            var categoryName = typeof(TestFilter).GetTypeInfo().FullName;
            var coreLogger   = new FakeCoreLogger();
            var logger       = new AWSLogger(
                categoryName,
                coreLogger,
                AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName));

            logger.LogTrace("trace");
            logger.LogDebug("debug");
            logger.LogInformation("information");
            logger.LogWarning("warning");
            logger.LogError("error");
            logger.LogCritical("critical");

            Assert.Equal(5, coreLogger.ReceivedMessages.Count);
            Assert.True(coreLogger.ReceivedMessages.Contains("warning\r\n"));
            Assert.True(coreLogger.ReceivedMessages.Contains("error\r\n"));
            Assert.True(coreLogger.ReceivedMessages.Contains("critical\r\n"));
        }
        public void MissingLogLevelCheck()
        {
            var configSection = LoggerConfigSectionSetup("MissingLogLevelCheck.json", null).GetSection("LogLevel");

            if (!(configSection != null && configSection.GetChildren().Count() > 0))
            {
                configSection = null;
            }
            var categoryName = typeof(TestFilter).GetTypeInfo().FullName;
            var coreLogger   = new FakeCoreLogger();
            var logger       = new AWSLogger(
                categoryName,
                coreLogger,
                AWSLoggerProvider.CreateConfigSectionFilter(configSection, categoryName));

            logger.LogTrace("trace");
            logger.LogDebug("debug");
            logger.LogInformation("information");
            logger.LogWarning("warning");
            logger.LogError("error");
            logger.LogCritical("critical");

            Assert.Equal(6, coreLogger.ReceivedMessages.Count);
            Assert.Contains($"[Warning] AWS.Logger.AspNetCore.Tests.TestFilter: warning{Environment.NewLine}", coreLogger.ReceivedMessages);
            Assert.Contains($"[Error] AWS.Logger.AspNetCore.Tests.TestFilter: error{Environment.NewLine}", coreLogger.ReceivedMessages);
            Assert.Contains($"[Critical] AWS.Logger.AspNetCore.Tests.TestFilter: critical{Environment.NewLine}", coreLogger.ReceivedMessages);
        }
Beispiel #4
0
        // Althrough scoping isn't currently supported make sure that at least it doesn't cause
        // issues if it is used.
        public void MakeSureCanCreateScope()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("MakeSureCanCreateScope", coreLogger, null);

            using (var scope = logger.BeginScope <TestScope>(this))
            {
                logger.LogInformation("log");
            }

            Assert.Equal(1, coreLogger.ReceivedMessages.Count);
            Assert.True(coreLogger.ReceivedMessages.Contains("log"));
        }
Beispiel #5
0
        // Make sure that a message will be logged inside a scope, even when scopes are not included.
        public void MakeSureCanCreateScope()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("MakeSureCanCreateScope", coreLogger, null)
            {
                IncludeScopes = false
            };

            using (logger.BeginScope("Test Scope"))
            {
                logger.LogInformation("log");
            }

            Assert.Single(coreLogger.ReceivedMessages);
            Assert.True(coreLogger.ReceivedMessages.Contains("log\r\n"), "Messages don't contain actual log message.");
        }
Beispiel #6
0
        // Make sure that a message will be logged outside a scope, even when scopes are included.
        public void MakeSureCanLogWithoutScope()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("MakeSureCanCreateScope", coreLogger, null)
            {
                IncludeScopes = true
            };

            logger.LogInformation("log");

            Assert.Single(coreLogger.ReceivedMessages);
            var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains($"[Information] MakeSureCanCreateScope: log{Environment.NewLine}"));

            Assert.True(msg != null, "Messages don't contain actual log message.");
            Assert.False(msg.Contains("=>"), "Fragment of scopes exists (\"=>\").");
        }
        public void FilterLogLevel()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("FilterLogLevel", coreLogger, AWSLoggerProvider.CreateLogLevelFilter(LogLevel.Warning));

            logger.LogTrace("trace");
            logger.LogDebug("debug");
            logger.LogInformation("information");
            logger.LogWarning("warning");
            logger.LogError("error");
            logger.LogCritical("critical");

            Assert.Equal(3, coreLogger.ReceivedMessages.Count);
            Assert.True(coreLogger.ReceivedMessages.Contains("warning\r\n"));
            Assert.True(coreLogger.ReceivedMessages.Contains("error\r\n"));
            Assert.True(coreLogger.ReceivedMessages.Contains("critical\r\n"));
        }
        public void FilterLogLevel()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("FilterLogLevel", coreLogger, AWSLoggerProvider.CreateLogLevelFilter(LogLevel.Warning));

            logger.LogTrace("trace");
            logger.LogDebug("debug");
            logger.LogInformation("information");
            logger.LogWarning("warning");
            logger.LogError("error");
            logger.LogCritical("critical");

            Assert.Equal(3, coreLogger.ReceivedMessages.Count);
            Assert.Contains($"[Warning] FilterLogLevel: warning{Environment.NewLine}", coreLogger.ReceivedMessages);
            Assert.Contains($"[Error] FilterLogLevel: error{Environment.NewLine}", coreLogger.ReceivedMessages);
            Assert.Contains($"[Critical] FilterLogLevel: critical{Environment.NewLine}", coreLogger.ReceivedMessages);
        }
Beispiel #9
0
        // Make sure that a message inside a scope will be logged together with the scope.
        public void MakeSureScopeIsIncluded()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("MakeSureCanCreateScope", coreLogger, null)
            {
                IncludeScopes = true
            };

            using (logger.BeginScope("Test scope"))
            {
                logger.LogInformation("log");
            }

            Assert.Single(coreLogger.ReceivedMessages);
            var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains("log\r\n"));

            Assert.True(msg != null, "Messages don't contain actual log message.");
            // Same message should contain the scope
            Assert.True(msg.Contains("=> Test scope: "), "Scope is not included.");
        }
Beispiel #10
0
        // Make sure that a message inside multiple scopes will be logged together with the scopes.
        public void MakeSureScopesAreIncluded()
        {
            var coreLogger = new FakeCoreLogger();
            var logger     = new AWSLogger("MakeSureCanCreateScope", coreLogger, null)
            {
                IncludeScopes = true
            };

            using (logger.BeginScope("OuterScope"))
            {
                using (logger.BeginScope("InnerScope"))
                {
                    logger.LogInformation("log");
                }
            }

            Assert.Single(coreLogger.ReceivedMessages);
            var msg = coreLogger.ReceivedMessages.SingleOrDefault(m => m.Contains($"[Information] OuterScope InnerScope => MakeSureCanCreateScope: log{Environment.NewLine}"));

            Assert.True(msg != null, "Messages don't contain actual log message.");
            // Same message should contain the scope
            Assert.True(msg.Contains("OuterScope"), "Outer scope is not included.");
            Assert.True(msg.Contains("InnerScope"), "Inner scope is not included.");
        }