LogHelper.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using SWRIS.Extensions;
  2. using System;
  3. using System.ComponentModel;
  4. namespace SWRIS.Core
  5. {
  6. public static class LogHelper
  7. {
  8. static LogHelper()
  9. {
  10. _logger.LogPath = FileHelper.GetPhysicalPath("Log");
  11. }
  12. public static string LogPath
  13. {
  14. set => _logger.LogPath = value;
  15. }
  16. public static void Info(string message, Exception exception = null)
  17. {
  18. _logger.Log(message, LogLevel.Info.GetDescription(), exception);
  19. }
  20. public static void Debug(string message, Exception exception = null)
  21. {
  22. _logger.Log(message, LogLevel.Debug.GetDescription(), exception);
  23. }
  24. public static void Warn(string message, Exception exception = null)
  25. {
  26. _logger.Log(message, LogLevel.Warn.GetDescription(), exception);
  27. }
  28. public static void Error(string message, Exception exception = null)
  29. {
  30. _logger.Log(message, LogLevel.Error.GetDescription(), exception);
  31. }
  32. public static void Fatal(string message, Exception exception = null)
  33. {
  34. _logger.Log(message, LogLevel.Fatal.GetDescription(), exception);
  35. }
  36. private static readonly SimpleLogger _logger = new SimpleLogger();
  37. private enum LogLevel
  38. {
  39. [Description("信息")]
  40. Info,
  41. [Description("调试")]
  42. Debug,
  43. [Description("警告")]
  44. Warn,
  45. [Description("错误")]
  46. Error,
  47. [Description("严重错误")]
  48. Fatal
  49. }
  50. }
  51. }