Beispiel #1
0
        public override void WriteEvent(LogEvent logEvent, byte[] messageBytes, int messageLength)
        {
            var stream = _stream;

            if (stream != null)
            {
                if (messageLength + 1 >= messageBytes.Length)
                {
                    throw new ApplicationException($"{nameof(messageBytes)} must be big enough to also contain the new line characters");
                }

                WritePrefix(stream, logEvent);

                NewlineBytes.CopyTo(messageBytes, messageLength);
                messageLength += NewlineBytes.Length;

                stream.Write(messageBytes, 0, messageLength);

                if (AutoFlush)
                {
                    stream.Flush();
                }

                _currentFileSize = (int)stream.Length;
                CheckRollFile();
            }
        }
Beispiel #2
0
        public override void WriteEvent(LogEvent logEvent, byte[] messageBytes, int messageLength)
        {
            Console.BackgroundColor = ConsoleColor.Black;
            switch (logEvent.Level)
            {
            case Level.Fatal:
                Console.ForegroundColor = ConsoleColor.Black;
                Console.BackgroundColor = ConsoleColor.White;
                break;

            case Level.Error:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case Level.Warn:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case Level.Info:
                Console.ForegroundColor = ConsoleColor.White;
                break;

            case Level.Debug:
                Console.ForegroundColor = ConsoleColor.Gray;
                break;

            case Level.Verbose:
                Console.ForegroundColor = ConsoleColor.Gray;
                break;

            case Level.Finest:
                Console.ForegroundColor = ConsoleColor.Gray;
                break;

            default:
                Console.ForegroundColor = ConsoleColor.White;
                break;
            }

            WritePrefix(_output, logEvent);

            NewlineBytes.CopyTo(messageBytes, messageLength);
            messageLength += NewlineBytes.Length;

            _output.Write(messageBytes, 0, messageLength);
        }