Пример #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);
        }
Пример #2
0
        public void TheLoggerShouldLogWithWarn()
        {
            var logger = new BaseLoggerMock { LoggingLevel = LogLevels.LogWarn };

            logger.Warn("test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(WARN) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogWarn, logger.ToWriteLevel);

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

            logger.WarnFormat("{0}", "test");
            Assert.AreEqual("test", logger.ToWrite);
            Assert.IsTrue(logger.ToWriteExpanded.IndexOf("(WARN) test") == START_OF_DATA_INDEX, logger.ToWriteExpanded);
            Assert.AreEqual(LogLevels.LogWarn, logger.ToWriteLevel);

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

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

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

            logger.Warn("test");
            logger.Warn("test", new Exception("testException"));
            logger.WarnFormat("{0}", "test");
            culture = CultureInfo.CreateSpecificCulture("en-US");
            logger.WarnFormat(culture, "{0}-{1}", "test", 0.2533);
            culture = CultureInfo.CreateSpecificCulture("it-IT");
            logger.WarnFormat(culture, "{0}-{1}", "test", 0.2533);
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
            Assert.IsNull(logger.ToWriteLevel);
        }
Пример #3
0
        public void TheLoggerShouldNotLogWithNone()
        {
            var logger = new BaseLoggerMock { LoggingLevel = LogLevels.LogNone };

            logger.Fatal("test");
            logger.Fatal("test", new Exception("testException"));
            logger.FatalFormat("{0}", "test");
            var culture = CultureInfo.CreateSpecificCulture("en-US");
            logger.FatalFormat(culture, "{0}-{1}", "test", 0.2533);
            culture = CultureInfo.CreateSpecificCulture("it-IT");
            logger.FatalFormat(culture, "{0}-{1}", "test", 0.2533);
            Assert.IsNull(logger.ToWrite);
            Assert.IsNull(logger.ToWriteExpanded);
        }
Пример #4
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);
        }