LogHelper.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using log4net;
  3. [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log.config", ConfigFileExtension = "config", Watch = true)]
  4. namespace Core.ONH.Collection.comm
  5. {
  6. public class LogHelper
  7. {
  8. /// <summary>
  9. /// 输出日志到Log4Net
  10. /// </summary>
  11. /// <param name="t"></param>
  12. /// <param name="ex"></param>
  13. #region static void WriteException(Type t, Exception ex)
  14. public static void WriteException(Type t, Exception ex)
  15. {
  16. ILog log = LogManager.GetLogger(t == null ? typeof(LogHelper) : t);
  17. log.Error("Error", ex);
  18. }
  19. #endregion
  20. /// <summary>
  21. /// 输出日志到Log4Net
  22. /// </summary>
  23. /// <param name="t"></param>
  24. /// <param name="msg"></param>
  25. #region static void WriteException(Type t, string msg)
  26. public static void WriteException(Type t, string msg)
  27. {
  28. ILog log = LogManager.GetLogger(t);
  29. log.Error(msg);
  30. }
  31. #endregion
  32. /// <summary>
  33. /// 输出日志到Log4Net
  34. /// </summary>
  35. /// <param name="t"></param>
  36. /// <param name="msg"></param>
  37. #region static void WriteException(Type t, string msg)
  38. public static void WriteInfo(Type t, string msg)
  39. {
  40. ILog log = LogManager.GetLogger(t);
  41. log.Info(msg);
  42. }
  43. #endregion
  44. }
  45. }