public void TestContingent() { var layout = new StandardLayout("${Message}${?Exception.Message:' | {0}'}"); string expectedWithError = "Hello, World! | Hello, Error!"; string actualWithError = layout.FormatLogEvent(new LogEvent { Message = "Hello, World!", Exception = new Exception("Hello, Error!") }); Assert.AreEqual(expectedWithError, actualWithError); string expectedWithoutError = "Hello, World!"; string actualWithoutError = layout.FormatLogEvent(new LogEvent { Message = "Hello, World!" }); Assert.AreEqual(expectedWithoutError, actualWithoutError); }
public void TestMessage() { var layout = new StandardLayout("${Message}"); string guid = Guid.NewGuid().ToString(); string actualString = layout.FormatLogEvent(new LogEvent { Message = guid }); Assert.AreEqual(guid, actualString); }
public void TestDateTimeFormat() { var layout = new StandardLayout("${DateTime:'{0:yyyyMMdd}'}"); var now = DateTime.Now; string actualString = layout.FormatLogEvent(new LogEvent { DateTime = now }); var expectedString = now.ToString("yyyyMMdd"); Assert.AreEqual(actualString, expectedString); }
public void TestTags() { var layout = new StandardLayout("${Tags}"); string expected = "this,is,a,test"; string actual = layout.FormatLogEvent(new LogEvent { Tags = new List<string> { "this", "is", "a", "test" } }); Assert.AreEqual(expected, actual); }
public void TestMetaData() { var layout = new StandardLayout("${HelloWorld:'{0}!'}"); var actual = layout.FormatLogEvent(new LogEvent { MetaData = new Dictionary<string, object> { {"HelloWorld", "Hello, World"} } }); var expected = "Hello, World!"; Assert.AreEqual(expected, actual); }