public void Error_LogAnonymousObjectOnEnabledLevel_LogsMessage() { var logger = new TestableLogger(Level.Error, _output); int number = Factory.GetInteger(); LoggerExtensions.Error(logger, new { message = "Hello", number }); Assert.Equal($"ERROR: {{\"message\":\"Hello\",\"number\":{number}}}", logger.Messages.First()); }
public void Error_LogAnonymousObjectOnEnabledLevel_VerifyLog() { var logMock = new Mock <ILogger>(); int number = Factory.GetInteger(); LoggerExtensions.Error(logMock.Object, new { message = "Hello", number }); logMock.VerifyLog <object>(Level.Error, Times.Once()); }
public void Error_LogAnonymousObjectAndExceptionOnEnabledLevel_VerifyLog() { var logMock = new Mock <ILogger>(); int number = Factory.GetInteger(); var exception = new Exception("OMG!"); LoggerExtensions.Error(logMock.Object, new { message = "Hello", number }, exception); logMock.VerifyLog <object, Exception>(Level.Error, exception, Times.Once()); }
public void Error_LazyLogAnonymousObjectOnEnabledLevel_CallMessageFormatter() { var isInvoked = false; var logger = new TestableLogger(Level.Error, _output); int state = Factory.GetInteger(); LoggerExtensions.Error(logger, state, number => { isInvoked = true; return(new { message = "Hello", number }); }); Assert.True(isInvoked); }
public void Error_LazyLogAnonymousObjectAndExceptionOnDisabledLevel_DoesNotCallMessageFormatter() { var isInvoked = false; var logger = new TestableLogger(Level.Critical, _output); int state = Factory.GetInteger(); LoggerExtensions.Error(logger, state, new Exception("OMG!"), (number, ex) => { isInvoked = true; return(new { message = "Hello", number }); }); Assert.False(isInvoked); }