Esempio n. 1
0
        public void should_trim_fields_that_are_too_long_at_any_depth()
        {
            var obj = new { Thing = new { Message = "A very long message that should be trimmed" } };

            var output = new List <ProcessedLogEvent>();
            var logger = new Logger(logEvents => logEvents
                                    .Select(BasicFormatting.Process)
                                    .Select(MessageTrimming.TrimFields(6))
                                    .Subscribe(log => output.Add(log))
                                    );

            logger.Info(obj);

            var message = ((Dictionary <string, object>)output[0].Content["Thing"])["Message"];

            Assert.Equal("A very", message);
        }
Esempio n. 2
0
        public void should_trim_fields_that_are_in_lists()
        {
            var obj = new { Thing = new[] { "A very long message that should be trimmed" } };

            var output = new List <ProcessedLogEvent>();
            var logger = new Logger(logEvents => logEvents
                                    .Select(BasicFormatting.Process)
                                    .Select(MessageTrimming.TrimFields(6))
                                    .Subscribe(log => output.Add(log))
                                    );

            logger.Info(obj);

            var message = ((IEnumerable <object>)output[0].Content["Thing"]).First();

            Assert.Equal("A very", message);
        }
Esempio n. 3
0
        public void should_trim_fields_that_are_too_long(string originalMessage, int trimLength, string trimmedMessage)
        {
            var obj = new { Message = originalMessage };

            var output = new List <ProcessedLogEvent>();
            var logger = new Logger(logEvents => logEvents
                                    .Select(BasicFormatting.Process)
                                    .Select(MessageTrimming.TrimFields(trimLength))
                                    .Subscribe(log => output.Add(log))
                                    );

            logger.Info(obj);

            var message = output[0].Content["Message"];

            Assert.Equal(trimmedMessage, message);
        }
Esempio n. 4
0
        public void should_leave_enums_ints_and_doubles_unaffected()
        {
            var obj = new { Message = "A very long message that should be trimmed", Number = 123456, Enumer = LogLevel.Error, Doub = 1234.56789 };

            var output = new List <ProcessedLogEvent>();
            var logger = new Logger(logEvents => logEvents
                                    .Select(BasicFormatting.Process)
                                    .Select(MessageTrimming.TrimFields(2))
                                    .Subscribe(log => output.Add(log))
                                    );

            logger.Info(obj);

            var number = output[0].Content["Number"];
            var enumer = output[0].Content["Enumer"];
            var doub   = output[0].Content["Doub"];

            Assert.Equal(123456, number);
            Assert.Equal(LogLevel.Error, enumer);
            Assert.Equal(1234.56789, doub);
        }