LogHelper.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using log4net;
  2. using System;
  3. [assembly: log4net.Config.XmlConfigurator(Watch = true)]
  4. namespace Muchinfo.PC.Common.Helpers
  5. {
  6. public class LogHelper
  7. {
  8. // private static Window1 window = null;
  9. /// <summary>
  10. /// 写错误日志
  11. /// </summary>
  12. /// <param name="message">The message.</param>
  13. public static void WriteError(Type t, string message)
  14. {
  15. //避免写日志循环
  16. try
  17. {
  18. var log = LogManager.GetLogger(t);
  19. if (log.IsErrorEnabled)
  20. {
  21. log.Error(message);
  22. }
  23. }
  24. catch
  25. {
  26. }
  27. }
  28. /// <summary>
  29. /// 写信息日志
  30. /// </summary>
  31. /// <param name="message">The message.</param>
  32. public static void WriteInfo(string message)
  33. {
  34. //避免写日志循环
  35. try
  36. {
  37. var log = LogManager.GetLogger(typeof(LogHelper));
  38. if (log.IsInfoEnabled)
  39. {
  40. log.Info(message);
  41. }
  42. }
  43. catch
  44. {
  45. }
  46. }
  47. }
  48. }