Esempio n. 1
0
        public void DoNotLogIfWrongType()
        {
            // Arrange
            FilteredStream fooStream = new FilteredStream {
                Types = new[] { "FooType" }
            };
            FilteredStream barStream = new FilteredStream {
                Types = new[] { "BarType" }
            };

            LogManager.Configuration
            .AddStream(fooStream)
            .AddStream(barStream)
            .SetLevel(ELogLevel.Debug);

            // Act
            ILog fooLog = LogManager.GetLog("FooType");
            ILog barLog = LogManager.GetLog("BarType");

            fooLog.Trace("foo");
            barLog.Trace("bar");
            string timestamp = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
            string tid       = Thread.CurrentThread.ManagedThreadId.ToString();

            // Assert
            string expFooVal     = $"TRACE {timestamp} [{tid}] FooType - foo\r\n";
            string expBarVal     = $"TRACE {timestamp} [{tid}] BarType - bar\r\n";
            string fooStreamData = fooStream.GetStreamData();
            string barStreamData = barStream.GetStreamData();

            Assert.AreEqual(expFooVal, fooStreamData);
            Assert.AreEqual(expBarVal, barStreamData);
        }