Esempio n. 1
0
        public void FilterLevel()
        {
            IDefaultActivityLogger l = DefaultActivityLogger.Create();

            // Binds the TestHelper.Logger logger to this one.
            l.Output.RegisterMuxClient(TestHelper.Logger.Output.ExternalInput);

            var log = new StringImpl();

            l.Register(log);
            using (l.Filter(LogLevelFilter.Error))
            {
                l.Trace("NO SHOW");
                l.Info("NO SHOW");
                l.Warn("NO SHOW");
                l.Error("Error n°1");
                using (l.Filter(LogLevelFilter.Warn))
                {
                    l.Trace("NO SHOW");
                    l.Info("NO SHOW");
                    l.Warn("Warn n°1");
                    l.Error("Error n°2");
                    using (l.OpenGroup(LogLevel.Info, "GroupInfo"))
                    {
                        Assert.That(l.Filter, Is.EqualTo(LogLevelFilter.Warn), "Groups does not change the current filter level.");
                        l.Trace("NO SHOW");
                        l.Info("NO SHOW");
                        l.Warn("Warn n°2");
                        l.Error("Error n°3");
                        // Changing the level inside a Group.
                        l.Filter = LogLevelFilter.Fatal;
                        l.Error("NO SHOW");
                        l.Fatal("Fatal n°1");
                    }
                    Assert.That(l.Filter, Is.EqualTo(LogLevelFilter.Warn), "But Groups restores the original filter level when closed.");
                    l.Trace("NO SHOW");
                    l.Info("NO SHOW");
                    l.Warn("Warn n°3");
                    l.Error("Error n°4");
                    l.Fatal("Fatal n°2");
                }
                l.Trace("NO SHOW");
                l.Info("NO SHOW");
                l.Warn("NO SHOW");
                l.Error("Error n°5");
            }
            Assert.That(log.Writer.ToString(), Is.Not.StringContaining("NO SHOW"));
            Assert.That(log.Writer.ToString(), Is.StringContaining("Error n°1")
                        .And.StringContaining("Error n°2")
                        .And.StringContaining("Error n°3")
                        .And.StringContaining("Error n°4")
                        .And.StringContaining("Error n°5"));
            Assert.That(log.Writer.ToString(), Is.StringContaining("Warn n°1")
                        .And.StringContaining("Warn n°2")
                        .And.StringContaining("Warn n°3"));
            Assert.That(log.Writer.ToString(), Is.StringContaining("Fatal n°1")
                        .And.StringContaining("Fatal n°2"));
        }