Ejemplo n.º 1
0
        public void ParametrizedScopeWrite()
        {
            var     logProcessor = new TestLogProcessor();
            ILogger logger       = new ColoredLogger("Test logger", new LoggerExternalScopeProvider(), logProcessor);

            using (logger.BeginParamScope(("testKey3", "testVal3"), ("testKey4", "testVal4")))
            {
                logger.LogInformation("Sample message");
            }

            var firstLogEntry = logProcessor.Log.FirstOrDefault();

            Assert.IsNotNull(firstLogEntry, "Log not passed to ILogProcessor");

            var logList = firstLogEntry.ToList();

            Assert.IsTrue(logList[0].String.StartsWith("[ INFO | 2 | "), "Incorrect 'header' start");
            Assert.IsNull(logList[0].BackgroundColor, "header BackgroundColor is not null");
            Assert.AreEqual(logList[0].ForegroundColor, ConsoleColor.Green, "header ForegroundColor color is not Green");
            Assert.IsTrue(logList[0].String.EndsWith("Test logger:\n"), "Incorrect 'header' end");

            Assert.AreEqual(logList[1].String, "testKey3: testVal3, testKey4: testVal4", "Incorrect 'scope'");

            Assert.AreEqual(logList[3].String, "testKey3: testVal3\ntestKey4: testVal4\n", "Incorrect 'params' from scope");

            Assert.AreEqual(logList[4].String, "Sample message", "Incorrect 'message'");
            Assert.AreEqual(logList[5].String, "\n", "Incorrect 'padding'");
        }
Ejemplo n.º 2
0
        public void SimpleWrite()
        {
            var     logProcessor = new TestLogProcessor();
            ILogger logger       = new ColoredLogger("Test logger", new LoggerExternalScopeProvider(), logProcessor);

            logger.LogInformation("Sample message");

            var firstLogEntry = logProcessor.Log.FirstOrDefault();

            Assert.IsNotNull(firstLogEntry, "Log not passed to ILogProcessor");

            var logList = firstLogEntry.ToList();

            Assert.IsTrue(logList[0].String.StartsWith("[ INFO | 2 | "), "Incorrect 'header' start");
            Assert.IsNull(logList[0].BackgroundColor, "header BackgroundColor is not null");
            Assert.AreEqual(logList[0].ForegroundColor, ConsoleColor.Green, "header ForegroundColor color is not Green");
            Assert.IsTrue(logList[0].String.EndsWith("Test logger:\n"), "Incorrect 'header' end");

            Assert.AreEqual(logList[1].String, "Sample message", "Incorrect 'message'");

            Assert.AreEqual(logList[2].String, "\n", "Incorrect 'padding'");
        }