Пример #1
0
        public void DoNotLogDebugOnInfoLevel()
        {
            // Arrange
            StringBuilderLogStream sbls = new StringBuilderLogStream();

            LogManager.Configuration
            .AddStream(sbls)
            .SetLevel(ELogLevel.Info);

            // Act
            ILog log = LogManager.GetLog(typeof(LogTests));

            log.Debug("An invisible entry.");

            // Assert
            string streamData = sbls.GetStreamData();

            Assert.IsEmpty(streamData);
        }
Пример #2
0
        public void LogInfo()
        {
            // Arrange
            StringBuilderLogStream sbls = new StringBuilderLogStream();

            LogManager.Configuration.AddStream(sbls);

            // Act
            ILog log = LogManager.GetLog(typeof(LogTests));

            log.Info("A simple log output.");
            string timestamp = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
            string tid       = Thread.CurrentThread.ManagedThreadId.ToString();

            // Assert
            string expVal = $"INFO {timestamp} [{tid}] LogTests - A simple log output.\r\n";

            string streamData = sbls.GetStreamData();

            Assert.AreEqual(expVal, streamData);
        }
Пример #3
0
        public void DoLogTraceOnDebugLevel()
        {
            // Arrange
            StringBuilderLogStream sbls = new StringBuilderLogStream();

            LogManager.Configuration
            .AddStream(sbls)
            .SetLevel(ELogLevel.Debug);

            // Act
            ILog log = LogManager.GetLog(typeof(LogTests));

            log.Trace("A trace record.");
            string timestamp = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
            string tid       = Thread.CurrentThread.ManagedThreadId.ToString();

            // Assert
            string expVal     = $"TRACE {timestamp} [{tid}] LogTests - A trace record.\r\n";
            string streamData = sbls.GetStreamData();

            Assert.AreEqual(expVal, streamData);
        }
Пример #4
0
        public void LogErrorWithException()
        {
            // Arrange
            StringBuilderLogStream sbls = new StringBuilderLogStream();

            LogManager.Configuration.AddStream(sbls);

            // Act
            ILog log = LogManager.GetLog(typeof(LogTests));

            log.Error("Something went wrong.", new InvalidOperationException("This should not have happen."));
            string timestamp = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
            string tid       = Thread.CurrentThread.ManagedThreadId.ToString();

            // Assert
            string streamData = sbls.GetStreamData();
            string expLine1   = $"ERROR {timestamp} [{tid}] LogTests - Something went wrong.\r\n";
            string expLine2   = $"ERROR {timestamp} [{tid}] LogTests - System.InvalidOperationException: This should not have happen.\r\n";

            Assert.IsTrue(streamData.Contains(expLine1));
            Assert.IsTrue(streamData.Contains(expLine2));
        }