Log.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using log4net;
  2. using log4net.Config;
  3. using System;
  4. using System.Diagnostics;
  5. using System.IO;
  6. namespace AIRS
  7. {
  8. /// <summary>
  9. /// function:Log
  10. /// author :lbf
  11. /// date :2020/6/17 17:31:13
  12. /// </summary>
  13. /// <summary>
  14. /// 使用Log4net插件的log日志对象
  15. /// </summary>
  16. public static class Log
  17. {
  18. private static ILog log;
  19. static Log()
  20. {
  21. XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
  22. log = LogManager.GetLogger(typeof(Log));
  23. }
  24. private static string getTraceMessage(object message)
  25. {
  26. var traceInfo = new StackTrace();
  27. return string.Format("[{0}-{1}] {2}", traceInfo.GetFrame(2).GetMethod().ReflectedType.Name, traceInfo.GetFrame(2).GetMethod().Name, message);
  28. }
  29. public static void Debug(object message)
  30. {
  31. log.Debug(getTraceMessage( message));
  32. }
  33. public static void DebugFormatted(string format, params object[] args)
  34. {
  35. log.DebugFormat(format, args);
  36. }
  37. public static void Info(object message)
  38. {
  39. log.Info(getTraceMessage(message));
  40. }
  41. public static void InfoFormatted(string format, params object[] args)
  42. {
  43. log.InfoFormat(format, args);
  44. }
  45. public static void Warn(object message)
  46. {
  47. log.Warn(getTraceMessage(message));
  48. }
  49. public static void Warn(object message, Exception exception)
  50. {
  51. log.Warn(getTraceMessage(message), exception);
  52. }
  53. public static void WarnFormatted(string format, params object[] args)
  54. {
  55. log.WarnFormat(format, args);
  56. }
  57. public static void Error(object message)
  58. {
  59. log.Error(getTraceMessage(message));
  60. }
  61. public static void Error(object message, Exception exception)
  62. {
  63. log.Error(message, exception);
  64. }
  65. public static void ErrorFormatted(string format, params object[] args)
  66. {
  67. log.ErrorFormat(format, args);
  68. }
  69. public static void Fatal(object message)
  70. {
  71. log.Fatal(getTraceMessage(message));
  72. }
  73. public static void Fatal(object message, Exception exception)
  74. {
  75. log.Fatal(getTraceMessage(message), exception);
  76. }
  77. public static void FatalFormatted(string format, params object[] args)
  78. {
  79. log.FatalFormat(format, args);
  80. }
  81. }
  82. }