logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1187391 - /logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs
Date Fri, 21 Oct 2011 15:14:06 GMT
Author: bodewig
Date: Fri Oct 21 15:14:05 2011
New Revision: 1187391

URL: http://svn.apache.org/viewvc?rev=1187391&view=rev
Log:
Proof XmlLayout properly deals with braces in stacktaces

Modified:
    logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs

Modified: logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs?rev=1187391&r1=1187390&r2=1187391&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs (original)
+++ logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs Fri Oct 21 15:14:05 2011
@@ -281,5 +281,56 @@ namespace log4net.Tests.Layout
 
 			Assert.AreEqual(expected, stringAppender.GetString());
 		}
+
+#if NET_4_0
+        [Test]
+        public void BracketsInStackTracesKeepLogWellFormed() {
+            XmlLayout layout = new XmlLayout();
+            StringAppender stringAppender = new StringAppender();
+            stringAppender.Layout = layout;
+
+            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+            BasicConfigurator.Configure(rep, stringAppender);
+            ILog log1 = LogManager.GetLogger(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());
+        }
+
+        [Test]
+        public void BracketsInStackTracesAreEscapedProperly() {
+            XmlLayout layout = new XmlLayout();
+            StringAppender stringAppender = new StringAppender();
+            stringAppender.Layout = layout;
+
+            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+            BasicConfigurator.Configure(rep, stringAppender);
+            ILog log1 = LogManager.GetLogger(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 startOfExceptionElement = log.IndexOf("<exception>");
+            var sub = log.Substring(startOfExceptionElement + 11);
+            StringAssert.StartsWith("System.NullReferenceException: Object reference not
set to an instance of an object", sub);
+            StringAssert.Contains("at log4net.Tests.Layout.XmlLayoutTest.&lt;&gt;c__DisplayClass4.&lt;BracketsInStackTracesAreEscapedProperly&gt;b__3(Int32
foo) in ", sub);
+        }
+#endif
 	}
 }
\ No newline at end of file



Mime
View raw message