From 994fc8dc2c933aaea284e8ed797aa7b100680795 Mon Sep 17 00:00:00 2001 From: DevWiki Date: Wed, 6 Apr 2022 22:28:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSocketTool/App.xaml.cs | 9 +++++++-- WebSocketTool/Util/Log.cs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/WebSocketTool/App.xaml.cs b/WebSocketTool/App.xaml.cs index 806de88..c428533 100644 --- a/WebSocketTool/App.xaml.cs +++ b/WebSocketTool/App.xaml.cs @@ -22,12 +22,17 @@ namespace WebSocketTool protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); - LogManager.GetManager().Init("WebSocketTool"); - XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config")); + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Directory.CreateDirectory("log"); + LogManager.GetManager().Init("WebSocketTool"); log = LogManager.GetManager().GetLog(nameof(App)); } + private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + log.Error($"app crash:{e.ExceptionObject}"); + } + public static void RunOnUIThread(Action action) { if (Current == null) diff --git a/WebSocketTool/Util/Log.cs b/WebSocketTool/Util/Log.cs index 44be902..57de6d1 100644 --- a/WebSocketTool/Util/Log.cs +++ b/WebSocketTool/Util/Log.cs @@ -104,7 +104,7 @@ namespace WebSocketTool.Util log.Warn(msg); } - public void Error(string msg, Exception e) + public void Error(string msg, Exception e = null) { log.Error(msg, e); }