/// <summary> /// 输出异常信息到日志 /// </summary> /// <param name="logEx"></param> public static void log(LogException logEx) { //记录异常到全局 GlobalCurrent.RUNTIME_LOGEXCEPTION_LIST.Add(logEx); //logEx.LogInnerException List<string> msgList = new List<string>(); recurInnerEx(logEx, (_logEx) => { msgList.Add(_logEx.LogMessage + _logEx.StackTrace); }, (_ex) => { msgList.Add(_ex.Message + _ex.StackTrace); }); //输出信息1 string msg = "#Exception : [ " + logEx.ExceptionTime + " ] [ " + logEx.ExceptionType + " ] [ " + logEx.TypeName + " ] "; //记录异常日志 //LogCommon.Instance.WriteLine(new string[] { msg, logEx.LogMessage }); LogCommon.Instance.WriteByAction((logWriter) => { logWriter.WriteLine(msg); foreach (string _msg in msgList) { logWriter.WriteLine(_msg); } }); }
/// <summary> /// 执行某个节点导致异常后的中断、继续判断 /// </summary> /// <param name="logEx"></param> public void handleRuntimeEx(LogException logEx) { Console.WriteLine("节点执行出现异常,是否中止执行:"); Console.WriteLine("--输入 continue 继续执行下面内容"); Console.WriteLine("--其他输入将中止执行"); //异常后接受输入字符,判断是否继续执行 if (Console.ReadLine() != "continue") { throw new LogException("ConfigAccess 执行节点失败", logEx); } else { LogOutput.logConsole(new LogException("ConfigAccess 执行节点失败", logEx)); } }
/// <summary> /// 输出异常信息到日志 /// </summary> /// <param name="logEx"></param> public static void logConsole(LogException logEx) { //输出到控制台 Console.WriteLine(logEx.LogMessage); log(logEx); }
/// <summary> /// 优先追溯LogException.LogInnerException /// </summary> /// <param name="logEx"></param> /// <param name="logExAction"></param> /// <param name="exAction"></param> public static void recurInnerEx(LogException logEx, Action<LogException> logExAction, Action<Exception> exAction) { // Action<string, string> action) {//List<string> msgList //处理LogException logExAction(logEx); if (logEx.LogInnerException is LogException) { recurInnerEx((LogException)logEx.LogInnerException, logExAction, exAction); } else if (logEx.LogInnerException != null && logEx.LogInnerException is Exception) { recurInnerEx(logEx.LogInnerException, logExAction, exAction); } }