From 2c88ae44a2b74ad0d105487347d0a6345539638e Mon Sep 17 00:00:00 2001 From: BlossomiShymae <87099578+BlossomiShymae@users.noreply.github.com> Date: Mon, 19 Aug 2024 02:58:36 -0500 Subject: [PATCH] Add unhandled exception logging --- Needlework.Net/Program.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Needlework.Net/Program.cs b/Needlework.Net/Program.cs index 46c9a8c..38c1470 100644 --- a/Needlework.Net/Program.cs +++ b/Needlework.Net/Program.cs @@ -6,6 +6,7 @@ using Needlework.Net.ViewModels; using Projektanker.Icons.Avalonia; using Projektanker.Icons.Avalonia.FontAwesome; using System; +using System.IO; namespace Needlework.Net; @@ -15,8 +16,13 @@ class Program // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. [STAThread] - public static void Main(string[] args) => BuildAvaloniaApp() + public static void Main(string[] args) + { + AppDomain.CurrentDomain.UnhandledException += Program_UnhandledException; + + BuildAvaloniaApp() .StartWithClassicDesktopLifetime(args); + } // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() @@ -43,4 +49,9 @@ class Program var services = builder.BuildServiceProvider(); return services; } + + private static void Program_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + File.WriteAllText($"errorlog-{DateTime.Now:HHmmssfff}", e.ExceptionObject.ToString()); + } }