ConsoleModbusLogger.cs 693 B

12345678910111213141516171819202122
  1. namespace NModbus.Logging
  2. {
  3. using System;
  4. public class ConsoleModbusLogger : ModbusLogger
  5. {
  6. private const int LevelColumnSize = 15;
  7. private static readonly string BlankHeader = Environment.NewLine + new string(' ', LevelColumnSize);
  8. public ConsoleModbusLogger(LoggingLevel minimumLoggingLevel = LoggingLevel.Debug)
  9. : base(minimumLoggingLevel)
  10. {
  11. }
  12. protected override void LogCore(LoggingLevel level, string message)
  13. {
  14. message = message?.Replace(Environment.NewLine, BlankHeader) ?? string.Empty;
  15. Console.WriteLine($"[{level}]".PadRight(LevelColumnSize) + message);
  16. }
  17. }
  18. }