Exemplo n.º 1
0
        public void Log4NetLogger_LoggingTest()
        {
            string    message       = "Error Message";
            Exception ex            = new Exception();
            string    messageFormat = "Message Format: message: {0}, exception: {1}";

            ILog log = new Log4NetLogger(GetType());

            Assert.IsNotNull(log);

            log.Debug(message);
            log.Debug(message, ex);
            log.DebugFormat(messageFormat, message, ex.Message);

            log.Error(message);
            log.Error(message, ex);
            log.ErrorFormat(messageFormat, message, ex.Message);

            log.Fatal(message);
            log.Fatal(message, ex);
            log.FatalFormat(messageFormat, message, ex.Message);

            log.Info(message);
            log.Info(message, ex);
            log.InfoFormat(messageFormat, message, ex.Message);

            log.Warn(message);
            log.Warn(message, ex);
            log.WarnFormat(messageFormat, message, ex.Message);
        }
        public void When_logging_using_error_format()
        {
            _logger.ErrorFormat("E:{0}", 1);
            _mockedLogger.Verify(l => l.ErrorFormat("E:{0}", 1), Times.Once);

            _logger.ErrorFormat("E:{0}, {1}", 1, 2);
            _mockedLogger.Verify(l => l.ErrorFormat("E:{0}, {1}", 1, 2), Times.Once);

            _logger.ErrorFormat("E:{0}, {1}, {2}", 1, 2, 3);
            _mockedLogger.Verify(l => l.ErrorFormat("E:{0}, {1}, {2}", 1, 2, 3), Times.Once);

            _logger.ErrorFormat("E:{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5);
            _mockedLogger.Verify(l => l.ErrorFormat("E:{0}, {1}, {2}, {3}, {4}", 1, 2, 3, 4, 5), Times.Once);

            var italianCulture = new CultureInfo("it-It");
            var date           = new DateTime(2000, 12, 28, 1, 4, 43, 0);

            _logger.ErrorFormat(italianCulture, "Date: {0}", date);
            _mockedLogger.Verify(l => l.ErrorFormat(italianCulture, "Date: {0}", date));
        }
Exemplo n.º 3
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            Assert.That(logMock.debug, Is.EqualTo(1));
            Assert.That(logMock.debugException, Is.EqualTo(1));
            Assert.That(logMock.debugFormat, Is.EqualTo(1));
            Assert.That(logMock.info, Is.EqualTo(1));
            Assert.That(logMock.infoException, Is.EqualTo(1));
            Assert.That(logMock.infoFormat, Is.EqualTo(1));
            Assert.That(logMock.warn, Is.EqualTo(1));
            Assert.That(logMock.warnException, Is.EqualTo(1));
            Assert.That(logMock.warnFormat, Is.EqualTo(1));
            Assert.That(logMock.error, Is.EqualTo(1));
            Assert.That(logMock.errorException, Is.EqualTo(1));
            Assert.That(logMock.errorFormat, Is.EqualTo(1));
            Assert.That(logMock.fatal, Is.EqualTo(1));
            Assert.That(logMock.fatalException, Is.EqualTo(1));
            Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
        }
Exemplo n.º 4
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            logMock.debug.Should().Be(1);
            logMock.debugException.Should().Be(1);
            logMock.debugFormat.Should().Be(1);
            logMock.info.Should().Be(1);
            logMock.infoException.Should().Be(1);
            logMock.infoFormat.Should().Be(1);
            logMock.warn.Should().Be(1);
            logMock.warnException.Should().Be(1);
            logMock.warnFormat.Should().Be(1);
            logMock.error.Should().Be(1);
            logMock.errorException.Should().Be(1);
            logMock.errorFormat.Should().Be(1);
            logMock.fatal.Should().Be(1);
            logMock.fatalException.Should().Be(1);
            logMock.isDebugEnabled.Should().Be.GreaterThan(1);
            logMock.isInfoEnabled.Should().Be.GreaterThan(1);
            logMock.isWarnEnabled.Should().Be.GreaterThan(1);
            logMock.isErrorEnabled.Should().Be.GreaterThan(1);
            logMock.isFatalEnabled.Should().Be.GreaterThan(1);
        }
Exemplo n.º 5
0
        public void Error_FormatMessage()
        {
            // Prepare
            const string format = "Number of Call: {0} occurred";

            logger.SetupGet(o => o.IsErrorEnabled).Returns(() => true);
            logger.Setup(o => o.ErrorFormat(format, new object[] { 1 })).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.ErrorFormat(format, 1);

            // Assert
            logger.VerifyAll();
        }
Exemplo n.º 6
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			logMock.debug.Should().Be(1);
			logMock.debugException.Should().Be(1);
			logMock.debugFormat.Should().Be(1);
			logMock.info.Should().Be(1);
			logMock.infoException.Should().Be(1);
			logMock.infoFormat.Should().Be(1);
			logMock.warn.Should().Be(1);
			logMock.warnException.Should().Be(1);
			logMock.warnFormat.Should().Be(1);
			logMock.error.Should().Be(1);
			logMock.errorException.Should().Be(1);
			logMock.errorFormat.Should().Be(1);
			logMock.fatal.Should().Be(1);
			logMock.fatalException.Should().Be(1);
			logMock.isDebugEnabled.Should().Be.GreaterThan(1);
			logMock.isInfoEnabled.Should().Be.GreaterThan(1);
			logMock.isWarnEnabled.Should().Be.GreaterThan(1);
			logMock.isErrorEnabled.Should().Be.GreaterThan(1);
			logMock.isFatalEnabled.Should().Be.GreaterThan(1);
		}
Exemplo n.º 7
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			Assert.That(logMock.debug, Is.EqualTo(1));
			Assert.That(logMock.debugException, Is.EqualTo(1));
			Assert.That(logMock.debugFormat, Is.EqualTo(1));
			Assert.That(logMock.info, Is.EqualTo(1));
			Assert.That(logMock.infoException, Is.EqualTo(1));
			Assert.That(logMock.infoFormat, Is.EqualTo(1));
			Assert.That(logMock.warn, Is.EqualTo(1));
			Assert.That(logMock.warnException, Is.EqualTo(1));
			Assert.That(logMock.warnFormat, Is.EqualTo(1));
			Assert.That(logMock.error, Is.EqualTo(1));
			Assert.That(logMock.errorException, Is.EqualTo(1));
			Assert.That(logMock.errorFormat, Is.EqualTo(1));
			Assert.That(logMock.fatal, Is.EqualTo(1));
			Assert.That(logMock.fatalException, Is.EqualTo(1));
			Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
		}
Exemplo n.º 8
0
        public void Error_FormatMessage()
        {
            // Prepare
            const string format = "Number of Call: {0} occurred";
            logger.SetupGet(o => o.IsErrorEnabled).Returns(() => true);
            logger.Setup(o => o.ErrorFormat(format, new object[] { 1 })).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.ErrorFormat(format, 1);

            // Assert
            logger.VerifyAll();
        }