From bb7c722e12836241faded90aba474ef45b1583a1 Mon Sep 17 00:00:00 2001 From: "terentev.a.a" Date: Wed, 4 Dec 2024 10:43:59 +0300 Subject: [PATCH] Add debug-specific configuration to Program.cs Introduced conditional compilation to execute additional logging and error handling specific to the debug build. This includes initializing Sentry, setting a default exception handler, and using `BuildAvaloniaApp` without parameters in the debug scenario, improving debugging efficiency and error traceability. --- src/Gml.Launcher/Program.cs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Gml.Launcher/Program.cs b/src/Gml.Launcher/Program.cs index 43da76f..efa8770 100644 --- a/src/Gml.Launcher/Program.cs +++ b/src/Gml.Launcher/Program.cs @@ -14,6 +14,24 @@ namespace Gml.Launcher; internal class Program { [STAThread] +#if DEBUG + public static void Main(string[] args) + { + try + { + Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Application started"); + InitializeSentry(); + RxApp.DefaultExceptionHandler = Observer.Create(GlobalExceptionHandler); + BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + } + catch (Exception exception) + { + SentrySdk.CaptureException(exception); + Console.WriteLine(exception); + } + } +#else public static void Main(string[] args) { try @@ -30,12 +48,25 @@ public static void Main(string[] args) Console.WriteLine(exception); } } +#endif private static void GlobalExceptionHandler(Exception exception) { SentrySdk.CaptureException(exception); } +#if DEBUG + public static AppBuilder BuildAvaloniaApp() + { + Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Configuring launcher"); + return AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .RegisterServices([]) + .LogToTrace() + .UseReactiveUI(); + } +#else public static AppBuilder BuildAvaloniaApp(string[] args) { Debug.WriteLine($"[Gml][{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] Configuring launcher"); @@ -46,8 +77,7 @@ public static AppBuilder BuildAvaloniaApp(string[] args) .LogToTrace() .UseReactiveUI(); } - - +#endif private static void InitializeSentry() {