Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }