LogHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using log4net;
  2. using log4net.Repository;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. namespace CZFW.CMS.Admin.App_Code
  8. {
  9. public static class InitRepository
  10. {
  11. public static ILoggerRepository loggerRepository { get; set; }
  12. }
  13. public static class LogHelper
  14. {
  15. public static readonly ILog logerror = log4net.LogManager.GetLogger(InitRepository.loggerRepository.Name, "logerror");
  16. public static readonly ILog loginfo = LogManager.GetLogger(InitRepository.loggerRepository.Name, "loginfo");
  17. #region 全局异常错误记录持久化
  18. /// <summary>
  19. /// 全局异常错误记录持久化
  20. /// </summary>
  21. /// <param name="throwMsg"></param>
  22. /// <param name="ex"></param>
  23. public static void ErrorLog(string throwMsg, Exception ex)
  24. {
  25. string errorMsg = string.Format("【抛出信息】:{0} \n【异常类型】:{1} \n【异常信息】:{2} \n【堆栈调用】:{3}", new object[] { throwMsg,
  26. ex.GetType().Name, ex.Message, ex.StackTrace });
  27. logerror.Error(errorMsg);
  28. }
  29. #endregion
  30. #region 自定义操作记录
  31. /// <summary>
  32. /// 自定义操作记录,与仓储中的增删改的日志是记录同一张表
  33. /// </summary>
  34. /// <param name="throwMsg"></param>
  35. /// <param name="ex"></param>
  36. public static void WriteLog(string throwMsg, Exception ex)
  37. {
  38. string errorMsg = string.Format("【抛出信息】:{0} \n【异常类型】:{1} \n【异常信息】:{2} \n【堆栈调用】:{3}", new object[] { throwMsg,
  39. ex.GetType().Name, ex.Message, ex.StackTrace });
  40. logerror.Error(errorMsg);
  41. }
  42. #endregion
  43. }
  44. }