Skip to content

Commit

Permalink
Add debug-specific configuration to Program.cs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gamer-VII committed Dec 4, 2024
1 parent 7c8e922 commit bb7c722
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/Gml.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>(GlobalExceptionHandler);
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch (Exception exception)
{
SentrySdk.CaptureException(exception);
Console.WriteLine(exception);
}
}
#else
public static void Main(string[] args)
{
try
Expand All @@ -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<App>()
.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");
Expand All @@ -46,8 +77,7 @@ public static AppBuilder BuildAvaloniaApp(string[] args)
.LogToTrace()
.UseReactiveUI();
}


#endif

private static void InitializeSentry()
{
Expand Down

0 comments on commit bb7c722

Please sign in to comment.