示例#1
0
        public virtual void TestNestedException()
        {
            Exception            e   = new NoRouteToHostException("that box caught fire 3 years ago");
            Exception            ioe = new IOException("Datacenter problems", e);
            ThrowableInformation ti  = new ThrowableInformation(ioe);
            Log4Json             l4j = new Log4Json();
            long   timeStamp         = Time.Now();
            string outcome           = l4j.ToJson(new StringWriter(), "testNestedException", timeStamp,
                                                  "INFO", "quoted\"", "new line\n and {}", ti).ToString();

            Println("testNestedException", outcome);
            ContainerNode rootNode = Log4Json.Parse(outcome);

            AssertEntryEquals(rootNode, Log4Json.Level, "INFO");
            AssertEntryEquals(rootNode, Log4Json.Name, "testNestedException");
            AssertEntryEquals(rootNode, Log4Json.Time, timeStamp);
            AssertEntryEquals(rootNode, Log4Json.ExceptionClass, ioe.GetType().FullName);
            JsonNode node = AssertNodeContains(rootNode, Log4Json.Stack);

            Assert.True("Not an array: " + node, node.IsArray());
            node = AssertNodeContains(rootNode, Log4Json.Date);
            Assert.True("Not a string: " + node, node.IsTextual());
            //rather than try and make assertions about the format of the text
            //message equalling another ISO date, this test asserts that the hypen
            //and colon characters are in the string.
            string dateText = node.GetTextValue();

            Assert.True("No '-' in " + dateText, dateText.Contains("-"));
            Assert.True("No '-' in " + dateText, dateText.Contains(":"));
        }
示例#2
0
        public virtual void TestConstruction()
        {
            Log4Json l4j     = new Log4Json();
            string   outcome = l4j.ToJson(new StringWriter(), "name", 0, "DEBUG", "thread1", "hello, world"
                                          , null).ToString();

            Println("testConstruction", outcome);
        }
示例#3
0
        public virtual void TestException()
        {
            Exception            e   = new NoRouteToHostException("that box caught fire 3 years ago");
            ThrowableInformation ti  = new ThrowableInformation(e);
            Log4Json             l4j = new Log4Json();
            long   timeStamp         = Time.Now();
            string outcome           = l4j.ToJson(new StringWriter(), "testException", timeStamp, "INFO"
                                                  , "quoted\"", "new line\n and {}", ti).ToString();

            Println("testException", outcome);
        }