public void should_log_to_file()
        {
            var bytes                 = new byte[256];
            var message               = "Test log message";
            var byteLength            = Encoding.Default.GetBytes(message, 0, message.Length, bytes, 0);
            var bufferSegmentProvider = new BufferSegmentProvider(1024, 1024);
            var logEvent              = new LogEvent(bufferSegmentProvider.GetSegment());

            logEvent.Initialize(Level.Info, new Log(null, "TestLog"));
            _appender.WriteEvent(logEvent, bytes, byteLength);
            _appender.Flush();

            var written = GetLastLine();

            Check.That(written).IsEqualTo($"{logEvent.Timestamp.Date:yyyy-MM-dd} - {logEvent.Timestamp.TimeOfDay.ToString(@"hh\:mm\:ss\.fff")} - {Thread.CurrentThread.ManagedThreadId} - Info - TestLog || " + message);
        }
Ejemplo n.º 2
0
        public void should_log_to_file()
        {
            var bytes      = new byte[256];
            var 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,
            };

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

            var written = GetLastLine();

            Check.That(written).IsEqualTo($"{logEventHeader.Timestamp.Date:yyyy-MM-dd} - {logEventHeader.Timestamp.TimeOfDay.ToString(@"hh\:mm\:ss\.fff")} - {logEventHeader.ThreadId} - INFO - TestLog || " + message);
        }