/// <summary> /// 错误日志 /// </summary> /// <param name="sender">this</param> /// <param name="plantCode">工厂编号</param> /// <param name="moduleCode">模块编号</param> /// <param name="exceptionCode">消息编码</param> /// <param name="eventType">事件类型</param> /// <param name="eventLevel">日志级别</param> /// <param name="eventName">日志名称</param> /// <param name="eventDescription">日志描述</param> /// <param name="listExternParas">扩展参数 最多三个</param> /// <param name="message">异常消息</param> /// <param name="ex">异常详细信息</param> public void LogError(object sender, string plantCode, string moduleCode, string exceptionCode, string eventType, EventLevel eventLevel, string eventName, string eventDescription, List <string> listExternParas, string message, Exception ex) { var model = new SysInfoProxy { Logid = Guid.NewGuid(), Plantcode = plantCode, OccurTime = DateTime.Now, Modulecode = moduleCode }; if (string.IsNullOrWhiteSpace(exceptionCode)) { string msg; if (ex == null) { msg = string.IsNullOrWhiteSpace(message) ? eventDescription : message; } else { msg = ex.StackTrace; } model.Eventlevel = eventLevel.ToString(); model.Eventdescription = msg; model.Eventname = eventName; model.Eventtype = eventType; } else { model.Exceptioncode = exceptionCode; model.Eventname = exceptionCode; } if (listExternParas != null) { if (listExternParas.Count == 1) { model.Para1 = listExternParas[0]; } if (listExternParas.Count == 2) { model.Para1 = listExternParas[1]; model.Para2 = listExternParas[2]; } if (listExternParas.Count == 3) { model.Para1 = listExternParas[0]; model.Para2 = listExternParas[1]; model.Para3 = listExternParas[2]; } } WriteSysLog(model); //非异常日志 不记录在本地 if (string.IsNullOrWhiteSpace(message) && ex == null) { this.Error(this, message, ex); } }
/// <summary> /// 记录系统日志 写数据库 /// </summary> /// <param name="model"></param> public void WriteSysLog(SysInfoProxy model) { if (!string.IsNullOrEmpty(model.Exceptioncode)) { var msgInfo = GetInfo(model.Exceptioncode); if (msgInfo != null) { model.Eventtype = msgInfo.Msgtype; model.Eventlevel = msgInfo.Defaultlevel; model.Eventdescription = msgInfo.Chncontent; model.Para1 = msgInfo.Parameter1; model.Para2 = msgInfo.Parameter2; model.Para3 = msgInfo.Parameter3; } } if (_sysLog != null && _sysLog.IsInfoEnabled) { _sysLog.Info(model); } }