예제 #1
0
        public void Information_LogAnonymousObjectOnEnabledLevel_LogsMessage()
        {
            var logger = new TestableLogger(Level.Information, _output);
            int number = Factory.GetInteger();

            LoggerExtensions.Information(logger, new { message = "Hello", number });
            Assert.Equal($"INFORMATION: {{\"message\":\"Hello\",\"number\":{number}}}", logger.Messages.First());
        }
        public void Critical_LogAnonymousObjectOnEnabledLevel_LogsMessage()
        {
            var logger = new TestableLogger(Level.Critical, _output);
            int number = Factory.GetInteger();

            LoggerExtensions.Critical(logger, new { message = "Hello", number });
            Assert.Equal($"CRITICAL: {{\"message\":\"Hello\",\"number\":{number}}}", logger.Messages.First());
        }
        public void Debug_LazyLogAnonymousObjectOnEnabledLevel_LogsMessage()
        {
            var logger = new TestableLogger(Level.Debug, _output);
            int state  = Factory.GetInteger();

            LoggerExtensions.Debug(logger, state, number => new { message = "Hello", number });
            Assert.Equal($"DEBUG: {{\"message\":\"Hello\",\"number\":{state}}}", logger.Messages.First());
        }
        public void Critical_LazyLogAnonymousObjectOnEnabledLevel_CallMessageFormatter()
        {
            bool isInvoked = false;
            var  logger    = new TestableLogger(Level.Critical, _output);
            int  state     = Factory.GetInteger();

            LoggerExtensions.Critical(logger, state, number =>
            {
                isInvoked = true;
                return(new { message = "Hello", number });
            });
            Assert.True(isInvoked);
        }
        public void Critical_LazyLogAnonymousObjectAndExceptionOnDisabledLevel_DoesNotCallMessageFormatter()
        {
            bool isInvoked = false;
            var  logger    = new TestableLogger((Level)1337, _output);
            int  state     = Factory.GetInteger();

            LoggerExtensions.Critical(logger, state, new Exception("OMG!"), (number, ex) =>
            {
                isInvoked = true;
                return(new { message = "Hello", number });
            });
            Assert.False(isInvoked);
        }
예제 #6
0
        public void Information_LazyLogAnonymousObjectOnDisabledLevel_DoesNotCallMessageFormatter()
        {
            var isInvoked = false;
            var logger    = new TestableLogger(Level.Error, _output);
            int state     = Factory.GetInteger();

            LoggerExtensions.Information(logger, state, number =>
            {
                isInvoked = true;
                return(new { message = "Hello", number });
            });
            Assert.False(isInvoked);
        }
예제 #7
0
        public void Information_LazyLogAnonymousObjectAndExceptionOnEnabledLevel_CallMessageFormatter()
        {
            var isInvoked = false;
            var logger    = new TestableLogger(Level.Information, _output);
            int state     = Factory.GetInteger();

            LoggerExtensions.Information(logger, state, new Exception("OMG!"), (number, ex) =>
            {
                isInvoked = true;
                return(new { message = "Hello", number });
            });
            Assert.True(isInvoked);
        }