protected override void RunTestLog(log4net.ILog log) { log4net.GlobalContext.Properties["OurCompany.ApplicationName"] = "fubar"; log.Info(4); var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); var procid = Process.GetCurrentProcess().Id; StringAssert.StartsWith(@"{""OurCompany.ApplicationName"":""fubar""", le, "log line"); StringAssert.Contains(@",""Host"":{", le, "log line"); StringAssert.Contains(@"""ProcessId"":" + procid, le, "log line"); StringAssert.Contains(@"""HostName"":""" + Environment.MachineName + @"""", le, "log line"); StringAssert.Contains(@"""A"":""L-INFO-log4net.Ext.Json.Xunit.Layout.Arrangements.Members""", le, "log line"); StringAssert.Contains(@"""B"":""" + DateTime.Now.Year + @"""", le, "log line"); StringAssert.Contains(@"""App"":""", le, "log line"); // fix #3, do not use member name as a default value StringAssert.DoesNotContain("empty1", le); StringAssert.DoesNotContain("empty2", le); }
protected override void RunTestLog(log4net.ILog log) { using (log4net.ThreadContext.Stacks["NDC"].Push("TestLog")) { log4net.ThreadContext.Properties["data"] = new { A = 1, B = new { X = "Y" } }; using (log4net.ThreadContext.Stacks["NDC"].Push("sub section")) { log.Info("OK"); } }; var events = GetEventStrings(log.Logger); Assert.AreEqual(1, events.Length, "events Count"); var le = events.Single(); Assert.IsNotNull(le, "loggingevent"); StringAssert.Contains(@"""data"":{", le, "le2 has structured message"); StringAssert.Contains(@"""X"":""Y""", le, "le2 has structured message"); StringAssert.Contains(@"""A"":1", le, "le2 has structured message"); StringAssert.Contains(@"""TestLog sub section""", le, "le1 has structured message"); StringAssert.DoesNotContain(@"""exception""", le, "le2 has no exception"); }