Пример #1
0
        public void TestClassLogger()
        {
            var inMemoryProvider = new InMemoryDatabaseProvider();

            TheLog.AddProvider(inMemoryProvider, LogLevel.Info);
            TheLog.FilterThreshold = LogLevel.Info;

            _logger.Info("Test");
            _logger.Trace("Test2");
            _logger.Error("Test");

            Assert.AreEqual(2, inMemoryProvider.Messages.Count);
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("LoggingTests"));

            inMemoryProvider.ClearLog();
            _logger.Error("Test", "ABC");
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("LoggingTests"));
            Assert.IsTrue(inMemoryProvider.Messages[0].LogMessage.Category.Contains("ABC"));
        }
Пример #2
0
        public void TestClassLoggerLevel()
        {
            TheLog.FilterThreshold = LogLevel.Trace;
            TheLog.AddProvider(InMemoryDatabaseProvider.TheOne, LogLevel.Trace);
            var database = InMemoryDatabaseProvider.TheOne;

            var classLogger = new ClassLogger(typeof(LoggingTests));

            classLogger.Trace("Test");
            Assert.AreEqual(LogLevel.Trace, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Debug("Test");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Info("Test");
            Assert.AreEqual(LogLevel.Info, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Warn("Test");
            Assert.AreEqual(LogLevel.Warn, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Error("Test");
            Assert.AreEqual(LogLevel.Error, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Fatal("Test");
            Assert.AreEqual(LogLevel.Fatal, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);

            classLogger.Log(LogLevel.Debug, "Message");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
        }