|
|
@ -15,6 +15,8 @@ using SlnMesnac.Common;
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
using System.Runtime.ExceptionServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF
|
|
|
|
namespace SlnMesnac.WPF
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -83,6 +85,7 @@ namespace SlnMesnac.WPF
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
HandleException(e.Exception);
|
|
|
|
HandleException(e.Exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -96,9 +99,29 @@ namespace SlnMesnac.WPF
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private static void HandleException(Exception ex)
|
|
|
|
private static void HandleException(Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Log.Warning($"全局异常捕获处理: {ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 记录异常的详细信息
|
|
|
|
|
|
|
|
Log.Warning($"全局异常捕获处理: {ex.Message}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取堆栈跟踪信息
|
|
|
|
|
|
|
|
StackTrace stackTrace = new StackTrace(ex, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历堆栈跟踪的每一帧
|
|
|
|
|
|
|
|
for (int i = 0; i < stackTrace.FrameCount; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StackFrame frame = stackTrace.GetFrame(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取文件名、行号和方法名
|
|
|
|
|
|
|
|
string fileName = frame.GetFileName();
|
|
|
|
|
|
|
|
int lineNumber = frame.GetFileLineNumber();
|
|
|
|
|
|
|
|
string methodName = frame.GetMethod().Name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 记录堆栈信息
|
|
|
|
|
|
|
|
Log.Warning($" 在文件 {fileName} 中,第 {lineNumber} 行,方法 {methodName} 抛出异常");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
|
|
|
|
//非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
|
|
|
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|