public void TestBase64EventLogging()
        {
            TextWriter writer = new StringWriter();
            XmlLayout  layout = new XmlLayout();
            var        ed     = new LoggingEventData();

            ed.Domain          = "tests";
            ed.ExceptionString = "";
            ed.Identity        = "testRunner";
            ed.Level           = Level.Info;
            ed.LocationInfo    = new LocationInfo(GetType());
            ed.LoggerName      = "testLogger";
            ed.Message         = "testMessage";
            ed.ThreadName      = "testThreadName";
            ed.TimeStampUtc    = DateTime.Now.ToUniversalTime();
            ed.UserName        = "******";
            ed.Properties      = new log4net.Util.PropertiesDictionary();

            ed.Message = "Base64EncodeMessage";
            layout.Base64EncodeMessage = true;

            layout.Format(writer, new LoggingEvent(ed));

            /*
             * <event logger="testLogger" timestamp="2018-09-07T17:34:09.3690143+08:00" level="INFO" thread="testThreadName" domain="tests" identity="testRunner" username="******"><message>QmFzZTY0RW5jb2RlTWVzc2FnZQ==</message></event>
             */

            Assert.IsTrue(writer.ToString().Contains("QmFzZTY0RW5jb2RlTWVzc2FnZQ=="));
        }
        public void TestBasicEventLogging()
        {
            TextWriter writer = new StringWriter();
            XmlLayout  layout = new XmlLayout();
            var        ed     = new LoggingEventData();

            ed.Domain          = "tests";
            ed.ExceptionString = "";
            ed.Identity        = "testRunner";
            ed.Level           = Level.Info;
            ed.LocationInfo    = new LocationInfo(GetType());
            ed.LoggerName      = "testLogger";
            ed.Message         = "testMessage";
            ed.ThreadName      = "testThreadName";
            ed.TimeStampUtc    = DateTime.Now.ToUniversalTime();
            ed.UserName        = "******";
            ed.Properties      = new log4net.Util.PropertiesDictionary();

            layout.Format(writer, new LoggingEvent(ed));

            /*
             *  <event logger="testLogger" timestamp="2018-09-07T14:23:41.5453462+08:00" level="INFO" thread="testThreadName" domain="tests" identity="testRunner" username="******">
             *          <message>testMessage</message>
             *  </event>
             */

            Assert.IsTrue(writer.ToString().Contains("testMessage"));
        }
        public void TestCDATAEscaping()
        {
            TextWriter writer = new StringWriter();
            XmlLayout  layout = new XmlLayout();
            var        ed     = new LoggingEventData();

            ed.Domain          = "tests";
            ed.ExceptionString = "";
            ed.Identity        = "testRunner";
            ed.Level           = Level.Info;
            ed.LocationInfo    = new LocationInfo(GetType());
            ed.LoggerName      = "testLogger";
            ed.Message         = "testMessage";
            ed.ThreadName      = "testThreadName";
            ed.TimeStampUtc    = DateTime.Now.ToUniversalTime();
            ed.UserName        = "******";
            ed.Properties      = new log4net.Util.PropertiesDictionary();

            //The &'s trigger the use of a cdata block
            ed.Message = "&&&&&&&Escape this ]]>. End here.";

            layout.Format(writer, new LoggingEvent(ed));

            /*
             * <event logger="testLogger" timestamp="2018-09-07T15:52:57.7039085+08:00" level="INFO" thread="testThreadName" domain="tests" identity="testRunner" username="******"><message><![CDATA[&&&&&&&Escape this ]]>]]<![CDATA[>. End here.]]></message></event>
             */

            Assert.IsTrue(writer.ToString().Contains("<![CDATA[&&&&&&&Escape this ]]>]]<![CDATA[>. End here.]]>"));
        }
Beispiel #4
0
        [Test] public void TestBasicEventLogging()
        {
            TextWriter       writer = new StringWriter();
            XmlLayout        layout = new XmlLayout();
            LoggingEventData evt    = createBaseEvent();

            layout.Format(writer, new LoggingEvent(evt));

            string expected = createEventNode("Test message");

            Assert.AreEqual(expected, writer.ToString());
        }
Beispiel #5
0
        [Test] public void TestBase64EventLogging()
        {
            TextWriter       writer = new StringWriter();
            XmlLayout        layout = new XmlLayout();
            LoggingEventData evt    = createBaseEvent();

            layout.Base64EncodeMessage = true;
            layout.Format(writer, new LoggingEvent(evt));

            string expected = createEventNode("VGVzdCBtZXNzYWdl");

            Assert.AreEqual(expected, writer.ToString());
        }
Beispiel #6
0
        [Test] public void TestIllegalCharacterMasking()
        {
            TextWriter       writer = new StringWriter();
            XmlLayout        layout = new XmlLayout();
            LoggingEventData evt    = createBaseEvent();

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

            layout.Format(writer, new LoggingEvent(evt));

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

            Assert.AreEqual(expected, writer.ToString());
        }
Beispiel #7
0
        [Test] public void TestCDATAEscaping3()
        {
            TextWriter       writer = new StringWriter();
            XmlLayout        layout = new XmlLayout();
            LoggingEventData evt    = createBaseEvent();

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

            layout.Format(writer, new LoggingEvent(evt));

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

            Assert.AreEqual(expected, writer.ToString());
        }
        public byte[] Build(LoggingEvent[] logs)
        {
            var sb = new StringBuilder();

            sb.AppendFormat(@"<?xml version=""1.0"" encoding=""{0}""?><events version=""1.2"" xmlns=""http://logging.apache.org/log4net/schemas/log4net-events-1.2"">", ContentEncoding);
            using (var sr = new StringWriter(sb))
            {
                foreach (LoggingEvent log in logs)
                {
                    _xmlLayout.Format(sr, log);
                }
            }
            sb.Append("</events>");
            return(_encoding.GetBytes(sb.ToString()));
        }