Example #1
0
        public void LogsMessage()
        {
            using var logger = new FellerConsoleLogger()
                  {
                      CategoryName = GetType().FullName.ToString()
                  };

            var timeOfLogCall = DateTime.Now;

            logger.LogInformation("Test message {TestValueA} {TestValueB}", 0.001, PrimaryColours.Red.ToString());

            string log = null;

            DefaultRetryPolicy.Execute(() =>
            {
                log = _consoleOutput.GetOuptut();
                return(!string.IsNullOrEmpty(log));
            });

            var deserialiedLog = JObject.Parse(log);

            Assert.IsTrue((timeOfLogCall - deserialiedLog.Value <DateTime>("Timestamp")).TotalMilliseconds < 5);
            Assert.AreEqual(0.001, deserialiedLog.Value <double>("TestValueA"));
            Assert.AreEqual(PrimaryColours.Red.ToString(), deserialiedLog.Value <string>("TestValueB"));
            Assert.AreEqual("Test message 0.001 Red", deserialiedLog.Value <string>("Message"));
            Assert.AreEqual(2, deserialiedLog.Value <int>("Level"));
            Assert.AreEqual("Feller.Tests.FellerConsoleLoggerTests", deserialiedLog.Value <string>("CategoryName"));
        }
Example #2
0
        public void LogsMessage()
        {
            using var logger = new FellerTestLogger()
                  {
                      CategoryName = GetType().FullName.ToString()
                  };

            var timeOfLogCall = DateTime.Now;

            logger.LogInformation("Test message {TestValueA} {TestValueB}", 0.001, PrimaryColours.Red.ToString());

            DefaultRetryPolicy.Execute(() => FellerTestLogger.Logs.Count > 1);
            FellerTestLogger.Logs.TryDequeue(out var log);

            Assert.IsNotNull(log);
            Assert.IsNotNull(log.Fields);
            Assert.IsTrue(log.Fields.Count == 6);

            Assert.IsTrue((timeOfLogCall - log.Timestamp.Value).TotalMilliseconds < 5);
            Assert.AreEqual(0.001, log.Fields["TestValueA"]);
            Assert.AreEqual(PrimaryColours.Red.ToString(), log.Fields["TestValueB"]);
            Assert.AreEqual("Test message 0.001 Red", log.Fields["Message"]);
            Assert.AreEqual(LogLevel.Information, log.Fields["Level"]);
        }