Log4Logger.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. namespace WWPipeLine.Commons
  3. {
  4. internal class Log4Logger : ILogger
  5. {
  6. private static log4net.ILog log = log4net.LogManager.GetLogger("Log");
  7. private static log4net.ILog logError = log4net.LogManager.GetLogger("LogError");
  8. public Log4Logger()
  9. {
  10. log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Paths.ApplicationConfigDir + "/log4net.xml"));
  11. }
  12. public void Debug(string message)
  13. {
  14. try
  15. {
  16. if (log.IsDebugEnabled)
  17. {
  18. log.Debug(message);
  19. }
  20. }
  21. catch
  22. {
  23. }
  24. }
  25. public void Shutdown()
  26. {
  27. log4net.LogManager.Shutdown();
  28. }
  29. public void Error(Exception ex)
  30. {
  31. try
  32. {
  33. if (logError.IsErrorEnabled)
  34. {
  35. logError.Error(ex);
  36. }
  37. }
  38. catch
  39. {
  40. }
  41. }
  42. public void Error(string message)
  43. {
  44. try
  45. {
  46. if (logError.IsErrorEnabled)
  47. {
  48. logError.Error(message);
  49. }
  50. }
  51. catch
  52. {
  53. }
  54. }
  55. public void Fatal(Exception ex)
  56. {
  57. try
  58. {
  59. if (logError.IsFatalEnabled)
  60. {
  61. logError.Fatal(ex);
  62. }
  63. }
  64. catch
  65. {
  66. }
  67. }
  68. public void Fatal(string message)
  69. {
  70. try
  71. {
  72. if (logError.IsFatalEnabled)
  73. {
  74. logError.Fatal(message);
  75. }
  76. }
  77. catch
  78. {
  79. }
  80. }
  81. public void Info(string message)
  82. {
  83. try
  84. {
  85. if (log.IsInfoEnabled)
  86. {
  87. log.Info(message);
  88. }
  89. }
  90. catch
  91. {
  92. }
  93. }
  94. public void Trace(string message)
  95. {
  96. Debug(message);
  97. }
  98. public void Warn(string message)
  99. {
  100. try
  101. {
  102. if (log.IsWarnEnabled)
  103. {
  104. log.Warn(message);
  105. }
  106. }
  107. catch
  108. {
  109. }
  110. }
  111. }
  112. }