Exemple #1
0
        public static void OnUnhandledException(Exception p_ex)
        {
            try
            {
                KnownException kex;
                if ((kex = p_ex as KnownException) != null || (kex = p_ex.InnerException as KnownException) != null)
                {
                    // 只警告,不保存日志
                    Kit.Warn(kex.Message);
                }
                else
                {
                    string title;
                    string msg;
                    if (p_ex is ServerException se)
                    {
                        title = se.Title;
                        msg   = se.Message;
                    }
                    else
                    {
                        title = "未处理异常";
                        msg   = $"异常消息:{p_ex.Message}\r\n堆栈信息:{p_ex.StackTrace}";
                    }

                    // 警告、输出监视、保存日志
                    var notify = new NotifyInfo
                    {
                        NotifyType   = NotifyType.Warning,
                        Message      = title,
                        DelaySeconds = 5,
                        Link         = "查看详细",
                    };
                    notify.LinkCallback = (e) =>
                    {
                        ShowTraceBox();
                        notify.Close();
                    };
                    SysVisual.NotifyList.Add(notify);
                    Kit.Trace(TraceOutType.UnhandledException, title, msg);
                    Log.Error(msg);
                }
            }
            catch { }
        }