Esempio n. 1
0
        public void BracketsInStackTracesKeepLogWellFormed()
        {
            LayoutLoggerXml layout         = new LayoutLoggerXml();
            StringAppender  stringAppender = new StringAppender();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog         log1 = LogManager.Get(rep.Name, "TestLogger");
            Action <int> bar  = foo => {
                try {
                    throw new NullReferenceException();
                } catch (Exception ex) {
                    log1.Error(string.Format("Error {0}", foo), ex);
                }
            };

            bar(42);

            // really only asserts there is no exception
            var loggedDoc = new XmlDocument();

            loggedDoc.LoadXml(stringAppender.GetString());
        }
Esempio n. 2
0
        public void TestBasicEventLogging()
        {
            TextWriter      writer = new StringWriter();
            LayoutLoggerXml layout = new LayoutLoggerXml();
            LogObjectData   evt    = CreateBaseEvent();

            layout.Format(writer, null, new LogObject(evt));

            string expected = CreateEventNode("Test message");

            Assert.AreEqual(expected, writer.ToString());
        }
Esempio n. 3
0
        public void TestBase64EventLogging()
        {
            TextWriter      writer = new StringWriter();
            LayoutLoggerXml layout = new LayoutLoggerXml();
            LogObjectData   evt    = CreateBaseEvent();

            layout.base64EncodeMessage = true;
            layout.Format(writer, null, new LogObject(evt));

            string expected = CreateEventNode("VGVzdCBtZXNzYWdl");

            Assert.AreEqual(expected, writer.ToString());
        }
Esempio n. 4
0
        public void TestIllegalCharacterMasking()
        {
            TextWriter      writer = new StringWriter();
            LayoutLoggerXml layout = new LayoutLoggerXml();
            LogObjectData   evt    = CreateBaseEvent();

            evt.Message = "This is a masked char->\uFFFF";

            layout.Format(writer, null, new LogObject(evt));

            string expected = CreateEventNode("This is a masked char-&gt;?");

            Assert.AreEqual(expected, writer.ToString());
        }
Esempio n. 5
0
        public void TestCDATAEscaping3()
        {
            TextWriter      writer = new StringWriter();
            LayoutLoggerXml layout = new LayoutLoggerXml();
            LogObjectData   evt    = CreateBaseEvent();

            //The &'s trigger the use of a cdata block
            evt.Message = "]]>&&&&&&&Escape the begining";

            layout.Format(writer, null, new LogObject(evt));

            string expected = CreateEventNode("<![CDATA[]]>]]<![CDATA[>&&&&&&&Escape the begining]]>");

            Assert.AreEqual(expected, writer.ToString());
        }
Esempio n. 6
0
        public void TestPropertyIllegalCharacterMaskingInName()
        {
            LogObjectData evt = CreateBaseEvent();

            evt.PropertySet["Property\uFFFF"] = "mask this ->\uFFFF";

            LayoutLoggerXml layout         = new LayoutLoggerXml();
            StringAppender  stringAppender = new StringAppender();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog log1 = LogManager.Get(rep.Name, "TestThreadProperiesPattern");

            log1.Logger.Log(new LogObject(evt));

            string expected = CreateEventNode("Property?", "mask this -&gt;?");

            Assert.AreEqual(expected, stringAppender.GetString());
        }
Esempio n. 7
0
        public void TestPropertyCharacterEscaping()
        {
            LogObjectData evt = CreateBaseEvent();

            evt.PropertySet["Property1"] = "prop1 \"quoted\"";

            LayoutLoggerXml layout         = new LayoutLoggerXml();
            StringAppender  stringAppender = new StringAppender();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog log1 = LogManager.Get(rep.Name, "TestThreadProperiesPattern");

            log1.Logger.Log(new LogObject(evt));

            string expected = CreateEventNode("Property1", "prop1 &quot;quoted&quot;");

            Assert.AreEqual(expected, stringAppender.GetString());
        }
Esempio n. 8
0
        public void BracketsInStackTracesAreEscapedProperly()
        {
            LayoutLoggerXml layout         = new LayoutLoggerXml();
            StringAppender  stringAppender = new StringAppender();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog         log1 = LogManager.Get(rep.Name, "TestLogger");
            Action <int> bar  = foo => {
                try {
                    throw new NullReferenceException();
                } catch (Exception ex) {
                    log1.Error(string.Format("Error {0}", foo), ex);
                }
            };

            bar(42);

            var log = stringAppender.GetString();
            var startOfExceptionText = log.IndexOf("<exception>", StringComparison.InvariantCulture) + 11;
            var endOfExceptionText   = log.IndexOf("</exception>", StringComparison.InvariantCulture);
            var sub = log.Substring(startOfExceptionText, endOfExceptionText - startOfExceptionText);

            if (sub.StartsWith("<![CDATA["))
            {
                StringAssert.EndsWith("]]>", sub);
            }
            else
            {
                StringAssert.DoesNotContain("<", sub);
                StringAssert.DoesNotContain(">", sub);
            }
        }
Esempio n. 9
0
        public void TestBase64PropertyEventLogging()
        {
            LogObjectData evt = CreateBaseEvent();

            evt.PropertySet["Property1"] = "prop1";

            LayoutLoggerXml layout = new LayoutLoggerXml();

            layout.base64EncodeProperties = true;
            StringAppender stringAppender = new StringAppender();

            stringAppender.Layout = layout;

            ILoggerController rep = LogManager.CreateController(Guid.NewGuid().ToString());

            BasicConfig.Config(rep, stringAppender);
            ILog log1 = LogManager.Get(rep.Name, "TestThreadProperiesPattern");

            log1.Logger.Log(new LogObject(evt));

            string expected = CreateEventNode("Property1", "cHJvcDE=");

            Assert.AreEqual(expected, stringAppender.GetString());
        }