using log4net; using log4net.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace CZFW.CMS.Admin.App_Code { public static class InitRepository { public static ILoggerRepository loggerRepository { get; set; } } public static class LogHelper { public static readonly ILog logerror = log4net.LogManager.GetLogger(InitRepository.loggerRepository.Name, "logerror"); public static readonly ILog loginfo = LogManager.GetLogger(InitRepository.loggerRepository.Name, "loginfo"); #region 全局异常错误记录持久化 /// /// 全局异常错误记录持久化 /// /// /// public static void ErrorLog(string throwMsg, Exception ex) { string errorMsg = string.Format("【抛出信息】:{0} \n【异常类型】:{1} \n【异常信息】:{2} \n【堆栈调用】:{3}", new object[] { throwMsg, ex.GetType().Name, ex.Message, ex.StackTrace }); logerror.Error(errorMsg); } #endregion #region 自定义操作记录 /// /// 自定义操作记录,与仓储中的增删改的日志是记录同一张表 /// /// /// public static void WriteLog(string throwMsg, Exception ex) { string errorMsg = string.Format("【抛出信息】:{0} \n【异常类型】:{1} \n【异常信息】:{2} \n【堆栈调用】:{3}", new object[] { throwMsg, ex.GetType().Name, ex.Message, ex.StackTrace }); logerror.Error(errorMsg); } #endregion } }