From 021f17aef41ef1a73f1a882aea66e074f9a30e30 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 18 Jun 2022 22:36:52 +0200 Subject: [PATCH] General - Log fatal exceptions on all platforms --- src/Artemis.UI.Linux/App.axaml.cs | 1 + src/Artemis.UI.Linux/Program.cs | 19 ++++++++++++++++++- src/Artemis.UI.MacOS/App.axaml.cs | 6 +++++- src/Artemis.UI.MacOS/Program.cs | 19 ++++++++++++++++++- src/Artemis.UI.Windows/App.axaml.cs | 2 +- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Artemis.UI.Linux/App.axaml.cs b/src/Artemis.UI.Linux/App.axaml.cs index 6a0f198c9..d5959c538 100644 --- a/src/Artemis.UI.Linux/App.axaml.cs +++ b/src/Artemis.UI.Linux/App.axaml.cs @@ -17,6 +17,7 @@ namespace Artemis.UI.Linux public override void Initialize() { _kernel = ArtemisBootstrapper.Bootstrap(this); + Program.CreateLogger(_kernel); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; AvaloniaXamlLoader.Load(this); diff --git a/src/Artemis.UI.Linux/Program.cs b/src/Artemis.UI.Linux/Program.cs index 35139d1e0..9df271766 100644 --- a/src/Artemis.UI.Linux/Program.cs +++ b/src/Artemis.UI.Linux/Program.cs @@ -1,6 +1,8 @@ using System; using Avalonia; using Avalonia.ReactiveUI; +using Ninject; +using Serilog; namespace Artemis.UI.Linux { @@ -12,7 +14,15 @@ namespace Artemis.UI.Linux [STAThread] public static void Main(string[] args) { - BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + try + { + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } + catch (Exception e) + { + Logger?.Fatal(e, "Fatal exception, shutting down"); + throw; + } } // Avalonia configuration, don't remove; also used by visual designer. @@ -20,5 +30,12 @@ namespace Artemis.UI.Linux { return AppBuilder.Configure().UsePlatformDetect().LogToTrace().UseReactiveUI(); } + + private static ILogger? Logger { get; set; } + + public static void CreateLogger(IKernel kernel) + { + Logger = kernel.Get().ForContext(); + } } } \ No newline at end of file diff --git a/src/Artemis.UI.MacOS/App.axaml.cs b/src/Artemis.UI.MacOS/App.axaml.cs index 2ba0b134e..4993d81c9 100644 --- a/src/Artemis.UI.MacOS/App.axaml.cs +++ b/src/Artemis.UI.MacOS/App.axaml.cs @@ -1,15 +1,19 @@ using Avalonia; using Avalonia.Markup.Xaml; using Avalonia.Threading; +using Ninject; using ReactiveUI; namespace Artemis.UI.MacOS { public class App : Application { + private StandardKernel? _kernel; + public override void Initialize() { - ArtemisBootstrapper.Bootstrap(this); + _kernel = ArtemisBootstrapper.Bootstrap(this); + Program.CreateLogger(_kernel); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; AvaloniaXamlLoader.Load(this); } diff --git a/src/Artemis.UI.MacOS/Program.cs b/src/Artemis.UI.MacOS/Program.cs index 1ac0ea168..efcc1561d 100644 --- a/src/Artemis.UI.MacOS/Program.cs +++ b/src/Artemis.UI.MacOS/Program.cs @@ -1,6 +1,8 @@ using System; using Avalonia; using Avalonia.ReactiveUI; +using Ninject; +using Serilog; namespace Artemis.UI.MacOS { @@ -12,7 +14,15 @@ namespace Artemis.UI.MacOS [STAThread] public static void Main(string[] args) { - BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + try + { + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + } + catch (Exception e) + { + Logger?.Fatal(e, "Fatal exception, shutting down"); + throw; + } } // Avalonia configuration, don't remove; also used by visual designer. @@ -20,5 +30,12 @@ namespace Artemis.UI.MacOS { return AppBuilder.Configure().UsePlatformDetect().LogToTrace().UseReactiveUI(); } + + private static ILogger? Logger { get; set; } + + public static void CreateLogger(IKernel kernel) + { + Logger = kernel.Get().ForContext(); + } } } \ No newline at end of file diff --git a/src/Artemis.UI.Windows/App.axaml.cs b/src/Artemis.UI.Windows/App.axaml.cs index 336bb3b37..6d5aa72e1 100644 --- a/src/Artemis.UI.Windows/App.axaml.cs +++ b/src/Artemis.UI.Windows/App.axaml.cs @@ -37,9 +37,9 @@ namespace Artemis.UI.Windows inputService.AddInputProvider(standardKernel.Get()); } - // ReSharper disable NotAccessedField.Local private StandardKernel? _kernel; + // ReSharper disable NotAccessedField.Local private ApplicationStateManager? _applicationStateManager; // ReSharper restore NotAccessedField.Local }