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); }