示例#1
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 "quoted"");

            Assert.AreEqual(expected, stringAppender.GetString());
        }
示例#2
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 ->?");

            Assert.AreEqual(expected, stringAppender.GetString());
        }
示例#3
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);
            }
        }
示例#4
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());
        }