Exemplo n.º 1
0
        public void TestLogger()
        {
            var sink   = new TestLoggerSink();
            var logger = new DefaultLogger.InternalLogger();

            using (logger.SetTempDestination(null))
            {
                sink.LastLevel.ShouldBeEquivalentTo(null);
                sink.LastMessage.ShouldBeEquivalentTo(null);

                logger.LogLevel.ShouldBeEquivalentTo(Defaults.DefaultLogLevel);
                logger.LogLevel = LogLevel.Debug;

                // null destination shouldn't throw
                logger.LoggerSink = null;
                logger.Debug("msg");

                logger.LoggerSink = sink;

                // Basic messages
                logger.Error("Test Error Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                logger.Debug("Test Info Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Info Message");

                logger.Debug("Test Debug Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Debug Message");

                // Verify the log level works
                logger.LogLevel = LogLevel.Warning;
                logger.Error("Test Error Message");
                logger.Debug("Test Info Message");
                logger.Debug("Test Debug Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                // Revert the level
                logger.LogLevel = Defaults.DefaultLogLevel;
            }

            // test that the Logger gets instanced
            Assert.NotNull(DefaultLogger.LoggerInstance);
        }
Exemplo n.º 2
0
        public void TestLogger()
        {
            var sink   = new TestLoggerSink();
            var logger = InternalLogger.Create();

            using (logger.CreateDisposableLoggingContext(null))
            {
                sink.LastLevel.Should().BeNull();
                sink.LastMessage.Should().BeNull();

                logger.LogLevel.Should().Be(Defaults.DefaultLogLevel);
                logger.LogLevel = LogLevel.Debug;

                // null destination shouldn't throw
                logger.LoggerSink = null;
                logger.Debug("msg");

                logger.LoggerSink = sink;

                // Basic messages
                logger.Error("Test Error Message");
                sink.LastLevel.Should().Be(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                logger.Debug("Test Info Message");
                sink.LastLevel.Should().Be(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Info Message");

                logger.Debug("Test Debug Message");
                sink.LastLevel.Should().Be(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Debug Message");

                // Verify the log level works
                logger.LogLevel = LogLevel.Warning;
                logger.Error("Test Error Message");
                logger.Debug("Test Info Message");
                logger.Debug("Test Debug Message");
                sink.LastLevel.Should().Be(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                // Revert the level
                logger.LogLevel = Defaults.DefaultLogLevel;
            }

            // test that the Logger gets instanced
            DefaultLogger.LoggerInstance.Should().NotBeNull();
        }
Exemplo n.º 3
0
        public void TestLogger()
        {
            var sink = new TestLoggerSink();

            using (Logger.SetTempDestination(null))
            {
                sink.LastLevel.ShouldBeEquivalentTo(null);
                sink.LastMessage.ShouldBeEquivalentTo(null);

                Logger.LogLevel.ShouldBeEquivalentTo(Defaults.DefaultLogLevel);
                Logger.LogLevel = LogLevel.Debug;

                // null destination shouldn't throw
                Logger.LoggerSink = null;
                Logger.Debug("msg");

                Logger.LoggerSink = sink;

                // Basic messages
                Logger.Error("Test Error Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                Logger.Debug("Test Info Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Info Message");

                Logger.Debug("Test Debug Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Debug);
                sink.LastMessage.Should().EndWith("Test Debug Message");

                // Verify the log level works
                Logger.LogLevel = LogLevel.Warning;
                Logger.Error("Test Error Message");
                Logger.Debug("Test Info Message");
                Logger.Debug("Test Debug Message");
                sink.LastLevel.ShouldBeEquivalentTo(LogLevel.Error);
                sink.LastMessage.Should().EndWith("Test Error Message");

                // Revert the level
                Logger.LogLevel = Defaults.DefaultLogLevel;
            }
        }