足力健后端,使用.netcore版本,合并1个项目使用

Logger.cs 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using NLog;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace System.Common
  6. {
  7. public class Logger
  8. {
  9. NLog.Logger _logger;
  10. public Logger(NLog.Logger logger)
  11. {
  12. _logger = logger;
  13. }
  14. public Logger(string name) : this(LogManager.GetLogger(name))
  15. {
  16. }
  17. public static Logger Default { get; private set; }
  18. static Logger()
  19. {
  20. Default = new Logger(NLog.LogManager.GetCurrentClassLogger());
  21. }
  22. #region Debug
  23. public void Debug(string msg, params object[] args)
  24. {
  25. _logger.Debug(msg, args);
  26. }
  27. public void Debug(string msg, Exception err)
  28. {
  29. _logger.Debug(err, msg);
  30. }
  31. #endregion
  32. #region Info
  33. public void Info(string msg, params object[] args)
  34. {
  35. _logger.Info(msg, args);
  36. }
  37. public void Info(string msg, Exception err)
  38. {
  39. _logger.Info(err, msg);
  40. }
  41. #endregion
  42. #region Warn
  43. public void Warn(string msg, params object[] args)
  44. {
  45. _logger.Warn(msg, args);
  46. }
  47. public void Warn(string msg, Exception err)
  48. {
  49. _logger.Warn(err, msg);
  50. }
  51. #endregion
  52. #region Trace
  53. public void Trace(string msg, params object[] args)
  54. {
  55. _logger.Trace(msg, args);
  56. }
  57. public void Trace(string msg, Exception err)
  58. {
  59. _logger.Trace(err, msg);
  60. }
  61. #endregion
  62. #region Error
  63. public void Error(string msg, params object[] args)
  64. {
  65. _logger.Error(msg, args);
  66. }
  67. public void Error(string msg, Exception err)
  68. {
  69. _logger.Error(err, msg);
  70. }
  71. #endregion
  72. #region Fatal
  73. public void Fatal(string msg, params object[] args)
  74. {
  75. _logger.Fatal(msg, args);
  76. }
  77. public void Fatal(string msg, Exception err)
  78. {
  79. _logger.Fatal(err, msg);
  80. }
  81. #endregion
  82. /// <summary&
  83. /// Flush any pending log messages (in case of asynchronous targets).
  84. /// </summary&
  85. /// <param name="timeoutMilliseconds"&Maximum time to allow for the flush. Any messages after that time will be discarded.</param&
  86. public void Flush(int? timeoutMilliseconds = null)
  87. {
  88. if (timeoutMilliseconds != null)
  89. NLog.LogManager.Flush(timeoutMilliseconds.Value);
  90. NLog.LogManager.Flush();
  91. }
  92. }
  93. }