From 6a503de26ef957281f5da5ad100730b2b480ddef Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Thu, 3 Jul 2025 12:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=AA=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index d4d8534..f5171aa 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -94,14 +94,14 @@ public partial class App : Application if (ex != null) { // 可以使用一个专用的 Logger 来记录未处理异常 - LogManager.GetLogger("UnhandledExceptionLogger").Fatal(ex, "应用程序发生未处理的异常。"); + LogManager.GetLogger("UnhandledExceptionLogger").Fatal($"应用程序发生未处理的异常:{ex}"); } }; // 捕获 Dispatcher 线程上的未处理异常 (UI 线程) this.DispatcherUnhandledException += (sender, args) => { - LogManager.GetLogger("DispatcherExceptionLogger").Fatal(args.Exception, "UI 线程发生未处理的异常。"); + LogManager.GetLogger("DispatcherExceptionLogger").Fatal( $"UI 线程发生未处理的异常:{args.Exception}"); // 标记为已处理,防止应用程序崩溃 (生产环境慎用,可能掩盖问题) // args.Handled = true; }; @@ -110,7 +110,7 @@ public partial class App : Application // 可以通过以下方式捕获 Task 中的异常。 TaskScheduler.UnobservedTaskException += (sender, args) => { - LogManager.GetLogger("UnobservedTaskExceptionLogger").Fatal(args.Exception, "异步任务发生未观察到的异常。"); + LogManager.GetLogger("UnobservedTaskExceptionLogger").Fatal( $"异步任务发生未观察到的异常:{args.Exception}"); // args.SetObserved(); // 标记为已观察,防止进程终止 };