Ejemplo n.º 1
0
        public void SimpleCollectorTest()
        {
            IDefaultActivityLogger d = DefaultActivityLogger.Create();
            var c = new ActivityLoggerSimpleCollector();

            d.Output.RegisterClient(c);
            d.Warn("1");
            d.Error("2");
            d.Fatal("3");
            d.Trace("4");
            d.Info("5");
            d.Warn("6");
            Assert.That(String.Join(",", c.Entries.Select(e => e.Text)), Is.EqualTo("2,3"));

            c.LevelFilter = LogLevelFilter.Fatal;
            Assert.That(String.Join(",", c.Entries.Select(e => e.Text)), Is.EqualTo("3"));

            c.LevelFilter = LogLevelFilter.Off;
            Assert.That(String.Join(",", c.Entries.Select(e => e.Text)), Is.EqualTo(""));

            c.LevelFilter = LogLevelFilter.Warn;
            using (d.OpenGroup(LogLevel.Warn, "1"))
            {
                d.Error("2");
                using (d.OpenGroup(LogLevel.Fatal, "3"))
                {
                    d.Trace("4");
                    d.Info("5");
                }
            }
            d.Warn("6");
            Assert.That(String.Join(",", c.Entries.Select(e => e.Text)), Is.EqualTo("1,2,3,6"));

            c.LevelFilter = LogLevelFilter.Fatal;
            Assert.That(String.Join(",", c.Entries.Select(e => e.Text)), Is.EqualTo("3"));
        }
Ejemplo n.º 2
0
        public void Overloads()
        {
            Exception ex = new Exception("EXCEPTION");
            string    fmt0 = "fmt", fmt1 = "fmt{0}", fmt2 = "fmt{0}{1}", fmt3 = "fmt{0}{1}{2}", fmt4 = "fmt{0}{1}{2}{3}", fmt5 = "fmt{0}{1}{2}{3}{4}", fmt6 = "fmt{0}{1}{2}{3}{4}{5}";
            string    p1 = "p1", p2 = "p2", p3 = "p3", p4 = "p4", p5 = "p5", p6 = "p6";

            IDefaultActivityLogger d = DefaultActivityLogger.Create();
            var collector            = new ActivityLoggerSimpleCollector()
            {
                LevelFilter = LogLevelFilter.Trace, Capacity = 1
            };

            d.Output.RegisterClient(collector);

            d.Trace(fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.Trace(fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.Trace(fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.Trace(fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.Trace(fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.Trace(fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.Trace(fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.Info(fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.Info(fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.Info(fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.Info(fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.Info(fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.Info(fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.Info(fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.Warn(fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.Warn(fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.Warn(fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.Warn(fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.Warn(fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.Warn(fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.Warn(fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.Error(fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.Error(fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.Error(fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.Error(fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.Error(fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.Error(fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.Error(fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.Fatal(fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.Fatal(fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.Fatal(fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.Fatal(fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.Fatal(fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.Fatal(fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.Fatal(fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.OpenGroup(LogLevel.Trace, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt"));
            d.OpenGroup(LogLevel.Trace, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1"));
            d.OpenGroup(LogLevel.Trace, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2"));
            d.OpenGroup(LogLevel.Trace, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3"));
            d.OpenGroup(LogLevel.Trace, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4"));
            d.OpenGroup(LogLevel.Trace, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5"));
            d.OpenGroup(LogLevel.Trace, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6"));

            d.Trace(ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Trace(ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));

            d.Info(ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Info(ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));

            d.Warn(ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Warn(ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));

            d.Error(ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Error(ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));

            d.Fatal(ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.Fatal(ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));

            d.OpenGroup(LogLevel.Trace, ex); Assert.That(collector.Entries.Last().Text, Is.EqualTo("EXCEPTION")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt0); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmt")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt1, p1); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt2, p1, p2); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt3, p1, p2, p3); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt4, p1, p2, p3, p4); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt5, p1, p2, p3, p4, p5); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
            d.OpenGroup(LogLevel.Trace, ex, fmt6, p1, p2, p3, p4, p5, p6); Assert.That(collector.Entries.Last().Text, Is.EqualTo("fmtp1p2p3p4p5p6")); Assert.That(collector.Entries.Last().Exception, Is.SameAs(ex));
        }