Esempio n. 1
0
        public void TheLoggerShouldConsiderLoggerLevelError()
        {
            var logger = new BaseLoggerMock { LoggingLevel = LogLevels.LogError };
            logger.Debug("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Info("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Warn("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Error("test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            logger.Fatal("test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(FATAL) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogFatal, logger.ToWriteLevel);
        }
Esempio n. 2
0
        public void TheLoggerShouldLogWithError()
        {
            var logger = new BaseLoggerMock { LoggingLevel = LogLevels.LogError };

            logger.Error("test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            logger.Error("test", new Exception("testException"));
            Assert.AreEqual("test\nSystem.Exception: testException", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test\nSystem.Exception: testException") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            logger.ErrorFormat("{0}", "test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            var culture = CultureInfo.CreateSpecificCulture("en-US");
            logger.ErrorFormat(culture, "{0}-{1}", "test", 0.2533);
            Assert.AreEqual("test-0.2533", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test-0.2533") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            culture = CultureInfo.CreateSpecificCulture("it-IT");
            logger.ErrorFormat(culture, "{0}-{1}", "test", 0.2533);
            Assert.AreEqual("test-0,2533", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(ERROR) test-0,2533") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogError, logger.ToWriteLevel);

            logger.LoggingLevel = LogLevels.LogFatal;
            logger.Reset();

            logger.Error("test");
            logger.Error("test", new Exception("testException"));
            logger.ErrorFormat("{0}", "test");
            culture = CultureInfo.CreateSpecificCulture("en-US");
            logger.ErrorFormat(culture, "{0}-{1}", "test", 0.2533);
            culture = CultureInfo.CreateSpecificCulture("it-IT");
            logger.ErrorFormat(culture, "{0}-{1}", "test", 0.2533);
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);
        }
Esempio n. 3
0
        public void TheLoggerShouldConsiderLoggerLevelNone()
        {
            var logger = new BaseLoggerMock { LoggingLevel = LogLevels.LogNone };
            logger.Debug("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Info("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Warn("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Error("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);

            logger.Fatal("test");
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);
        }