示例#1
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"));
        }
示例#2
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("Outer scope"))
            {
                using (logger.BeginScope("Inner 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("=> Outer scope"), "Outer scope is not included.");
            Assert.True(msg.Contains("=> Inner scope: "), "Inner scope is not included.");
        }
示例#3
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.");
        }
示例#4
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($"[Information] Test scope => 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("Test scope => "), "Scope is not included.");
        }