/// <summary> /// 记录异常的外部信息 /// </summary> /// <param name="ex"> 异常 </param> /// <returns> </returns> public static string ExceptionMessage(Exception ex) { if (ex != null) { #if !NETSTANDARD2_0 if (ex is SqlException) { return(AgebullSystemException.SqlExceptionLevel(ex as SqlException) > 16 ? String.Format("发生服务器错误,系统标识:{0}", GetRequestId()) : String.Format("发生服务器错误,{1},系统标识:{0}", GetRequestId(), ex.Message)); } #endif if (ex is SystemException) { return(String.Format("发生系统错误,系统标识:{0}", GetRequestId())); } if (ex is AgebullSystemException) { return(String.Format("发生内部错误,系统标识:{0}", GetRequestId())); } if (ex is BugException) { return(String.Format("发生设计错误,系统标识:{0}", GetRequestId())); } if (ex is AgebullBusinessException) { return(String.Format("发生业务逻辑错误,内容为:{1},系统标识:{0}", GetRequestId(), ex.Message)); } #if !NETSTANDARD2_0 return(String.Format("发生未知错误,系统标识:{0}", GetRequestId())); #endif } return("发生未处理异常"); }
/// <summary> /// 记录异常的外部信息 /// </summary> /// <param name="id"> 日志查询标识 </param> /// <param name="ex"> 异常 </param> /// <returns> </returns> public static string ExceptionMessage(Guid id, Exception ex) { if (ex != null) { #if SERVICE if (ex is SqlException) { return(AgebullSystemException.SqlExceptionLevel(ex as SqlException) > 16 ? String.Format("发生服务器错误,系统标识:{0}", id) : String.Format("发生服务器错误,{1},系统标识:{0}", id, ex.Message)); } #endif if (ex is SystemException) { return(String.Format("发生系统错误,系统标识:{0}", id)); } if (ex is AgebullSystemException) { return(String.Format("发生内部错误,系统标识:{0}", id)); } if (ex is BugException) { return(String.Format("发生设计错误,系统标识:{0}", id)); } if (ex is AgebullBusinessException) { return(String.Format("发生业务逻辑错误,内容为:{1},系统标识:{0}", id, ex.Message)); } #if SERVICE return(String.Format("发生未知错误,系统标识:{0}", id)); #endif } return("发生未处理异常"); }
/// <summary> /// 记录异常日志 /// </summary> /// <param name="lc"> 上下文 </param> /// <param name="e"> 异常 </param> public string Exception(LogContent lc, Exception e) { string re = "发生未处理异常"; if (lc == null) { lc = LogContent.Content; } if (e != null) { if (e is SqlException) { if (AgebullSystemException.SqlExceptionLevel(e as SqlException) > 16) { lc.Infomation = "内部错误"; re = string.Format("发生内部错误,系统标识:{0}", lc.QueryKey); } else { re = string.Format("{1},系统标识:{0}", lc.QueryKey, e.Message); } } else if (e is SystemException) { lc.Infomation = "系统错误"; re = string.Format("发生内部错误,系统标识:{0}", lc.QueryKey); } else if (e is AgebullSystemException) { lc.Infomation = "系统错误"; re = string.Format("发生内部错误,系统标识:{0}", lc.QueryKey); } else if (e is BugException) { lc.Infomation = "设计错误"; re = string.Format("发生设计错误,系统标识:{0}", lc.QueryKey); } else if (e is AgebullBusinessException) { lc.Infomation = e.Message; re = string.Format("{1},系统标识:{0}", lc.QueryKey, e.Message); } else { re = string.Format("发生未知错误,系统标识:{0}", lc.QueryKey); } lc.LocaleObject.Add(new LocaleItem { Name = "Exception", Value = e, Description = lc.Infomation }); } this.Log.Error(lc, e); return(re); }
/// <summary> /// 记录异常的详细信息 /// </summary> /// <param name="ex"> </param> /// <param name="message"> </param> /// <param name="xml"> </param> /// <returns> </returns> public static string ExceptionInfomation(Exception ex, string message, out string xml) { string outmsg = "发生未处理异常"; string tag = ""; if (ex != null) { if (ex is AgebullSystemException) { tag = "系统致命错误"; outmsg = String.Format("发生内部错误,系统标识:{0}", GetRequestId()); } else if (ex is BugException) { tag = "存在设计缺陷"; outmsg = String.Format("发生设计错误,系统标识:{0}", GetRequestId()); } else if (ex is AgebullBusinessException) { tag = "业务逻辑错误"; outmsg = String.Format("发生错误,内容为:{1},系统标识:{0}", GetRequestId(), ex.Message); } #if !NETSTANDARD2_0 else if (ex is SqlException) { if (AgebullSystemException.SqlExceptionLevel(ex as SqlException) > 16) { tag = "数据库致命错误(级别大于16)"; outmsg = String.Format("发生服务器错误,系统标识:{0}", GetRequestId()); } else { tag = "数据库一般错误(级别小等于16)"; outmsg = String.Format("发生服务器错误,{1},系统标识:{0}", GetRequestId(), ex.Message); } } #endif else if (ex is SystemException) { tag = "系统错误"; outmsg = String.Format("发生系统错误,系统标识:{0}", GetRequestId()); } else { tag = "未知错误"; outmsg = String.Format("发生未知错误,系统标识:{0}", GetRequestId()); } } XElement element = new XElement("ExceptionInfomation", new XElement("ID", GetRequestId()), new XElement("Tag", tag), new XElement("RecordType", "Exception"), new XElement("OutMessage", outmsg)); if (!string.IsNullOrWhiteSpace(message)) { if (message[0] == '<') { try { element.Add(new XElement("Tag", new XElement(message))); } catch { element.Add(new XElement("Message", message)); } } else { element.Add(new XElement("Message", message)); } } if (ex != null) { ReflectionHelper.SerializeException(ex, element); } xml = element.ToString(SaveOptions.None); return(outmsg); }