You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

8 months ago
  1. using NLog;
  2. using System;
  3. namespace Mirle.Component.Record
  4. {
  5. /// <summary>
  6. /// 記錄及顯示擴充方法類別
  7. /// </summary>
  8. public static class LogConsoleExtension
  9. {
  10. /// <summary>
  11. /// 紀錄及顯示訊息
  12. /// </summary>
  13. /// <param name="log">記錄器</param>
  14. /// <param name="message">紀錄訊息</param>
  15. /// <param name="loglevel">紀錄等級</param>
  16. public static void LogConsole(this Logger log, string message, LogLevel loglevel)
  17. {
  18. if (loglevel == LogLevel.Info)
  19. {
  20. Console.WriteLine(message);
  21. log.Info(message);
  22. }
  23. else if (loglevel == LogLevel.Debug)
  24. {
  25. Console.WriteLine(message);
  26. log.Debug(message);
  27. }
  28. else if (loglevel == LogLevel.Trace)
  29. {
  30. Console.WriteLine(message);
  31. log.Trace(message);
  32. }
  33. else if (loglevel == LogLevel.Warn)
  34. {
  35. Console.WriteLine(message);
  36. log.Warn(message);
  37. }
  38. else if (loglevel == LogLevel.Error)
  39. {
  40. Console.WriteLine(message);
  41. log.Error(message);
  42. }
  43. else
  44. {
  45. Console.WriteLine(message);
  46. log.Fatal(message);
  47. }
  48. }
  49. }
  50. }