Exemplo n.º 1
0
        public void CustomObjectAddedAsAdditionalProperties()
        {
            var layout = new GelfLayout();

            var message = new { Test = 1, Test2 = "YES!!!" };
            var loggingEvent = GetLogginEvent(message);

            var result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result["_Test"], message.Test.ToString());
            Assert.AreEqual(result["_Test2"], message.Test2);
        }
Exemplo n.º 2
0
        public void ToStringOnObjectIfNoMessageIsProvided()
        {
            var layout = new GelfLayout();

            var message = new { Test = 1, Test2 = 2 };

            var loggingEvent = GetLogginEvent(message);

            var result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result["_Test"], message.Test.ToString());
            Assert.AreEqual(result["_Test2"], message.Test2.ToString());
            Assert.AreEqual(result.FullMessage, message.ToString());
            Assert.AreEqual(result.ShortMessage, message.ToString().TruncateMessage(250));
        }
Exemplo n.º 3
0
        public void PatternConversionInAdditionalPropertiesWithCustomFieldSeparator()
        {
            var layout = new GelfLayout();
            layout.FieldSeparator = "||";
            layout.AdditionalFields = "Level:%level||AppDomain:%a||LoggerName:%c{1}||ThreadName:%t";
            var message = new { Message = "Test" };

            var loggingEvent = GetLogginEvent(message);

            var result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result["_Level"], "DEBUG");
            Assert.IsTrue(!string.IsNullOrWhiteSpace(result["_AppDomain"].ToString()));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(result["_ThreadName"].ToString()));
            Assert.AreEqual("Class", result["_LoggerName"]);
        }
Exemplo n.º 4
0
        public void PatternConversionLayoutSpecified()
        {
            var layout = new GelfLayout();
            layout.ConversionPattern = "[%level] - [%c{1}]";
            var message = new { Message = "Test" };

            var loggingEvent = GetLogginEvent(message);

            var result = GetMessage(layout, loggingEvent);

            Assert.AreEqual("[DEBUG] - [Class]", result["full_message"]);
            Assert.AreEqual("[DEBUG] - [Class]", result["short_message"]);
        }
Exemplo n.º 5
0
        public void CustomObjectWithShortMessageProperty()
        {
            var layout = new GelfLayout();
            var message = new { ShortMessage = "Success", Test = 1 };

            var loggingEvent = GetLogginEvent(message);
            var result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result.ShortMessage, message.ShortMessage);
            Assert.AreEqual(result["_Test"], message.Test.ToString());

            var message2 = new { short_message = "Success", Test = 1 };
            loggingEvent = GetLogginEvent(message2);
            result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result.ShortMessage, message2.short_message);
            Assert.AreEqual(result["_Test"], message2.Test.ToString());

            var message3 = new { message = "Success", Test = 1 };
            loggingEvent = GetLogginEvent(message3);
            result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result.FullMessage, message3.message);
            Assert.AreEqual(result.ShortMessage, message3.message);
            Assert.AreEqual(result["_Test"], message3.Test.ToString());

            var message4 = new { message = "Success", short_message = "test", Test = 1 };
            loggingEvent = GetLogginEvent(message4);
            result = GetMessage(layout, loggingEvent);

            Assert.AreEqual(result.FullMessage, message4.message);
            Assert.AreEqual(result.ShortMessage, message4.short_message);
            Assert.AreEqual(result["_Test"], message4.Test.ToString());
        }