Пример #1
0
        public void should_append_with_empty_prefix()
        {
            var          bytes      = new byte[256];
            const string message    = "Test log message";
            var          byteLength = Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);

            var logEventHeader = new LogEventHeader();
            var appender       = new MemoryAppender("");

            appender.WriteEvent(logEventHeader, bytes, byteLength);
            appender.WriteEvent(logEventHeader, bytes, byteLength);
            appender.Flush();

            var logLine = $"{message}{Environment.NewLine}";

            Check.That(appender.ToString()).IsEqualTo(logLine + logLine);
        }
Пример #2
0
        public void should_append_newline_even_when_there_are_not_enough_bytes_left_in_buffer()
        {
            var          bytes   = new byte[4];
            const string message = "Fooo";

            var logEventHeader = new LogEventHeader();
            var appender       = new MemoryAppender("");

            Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);
            appender.WriteEvent(logEventHeader, bytes, 2);

            Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);
            appender.WriteEvent(logEventHeader, bytes, 3);

            Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);
            appender.WriteEvent(logEventHeader, bytes, 4);

            appender.Flush();

            Check.That(appender.ToString()).IsEqualTo($"Fo{Environment.NewLine}Foo{Environment.NewLine}Fooo{Environment.NewLine}");
        }
Пример #3
0
        public void should_append()
        {
            var          bytes      = new byte[256];
            const string message    = "Test log message";
            var          byteLength = Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);

            var logEventHeader = new LogEventHeader
            {
                Level     = Level.Info,
                Name      = "TestLog",
                ThreadId  = 42,
                Timestamp = DateTime.UtcNow,
            };

            var appender = new MemoryAppender("%date - %time - %thread - %level - %logger || ");

            appender.WriteEvent(logEventHeader, bytes, byteLength);
            appender.WriteEvent(logEventHeader, bytes, byteLength);
            appender.Flush();

            var logLine = $"{logEventHeader.Timestamp.Date:yyyy-MM-dd} - {logEventHeader.Timestamp.TimeOfDay:hh\\:mm\\:ss\\.fffffff} - {logEventHeader.ThreadId} - INFO - TestLog || {message}{Environment.NewLine}";

            Check.That(appender.ToString()).IsEqualTo(logLine + logLine);
        }