Skip to content

Commit

Permalink
fix: add unhandled exceptions to logger
Browse files Browse the repository at this point in the history
Refs #123
  • Loading branch information
DorielRivalet committed Jul 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent bbfb0f6 commit a640106
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions MHFZ_Overlay/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// © 2023 The mhfz-overlay developers.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

// TODO: all of this needs testing
namespace MHFZ_Overlay;

using System;
using System.Configuration;
using System.Diagnostics;
@@ -11,19 +15,18 @@
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using MHFZ_Overlay.Models.Constant;
using MHFZ_Overlay.Services.Manager;
using Squirrel;

// TODO: all of this needs testing
namespace MHFZ_Overlay;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

public static bool isClowdSquirrelUpdating;

/// <summary>
@@ -48,6 +51,7 @@ protected override void OnStartup(StartupEventArgs e)
{
// Create a Stopwatch instance
Stopwatch stopwatch = new Stopwatch();

// Start the stopwatch
stopwatch.Start();
var loggingRules = NLog.LogManager.Configuration.LoggingRules;
@@ -62,7 +66,7 @@ protected override void OnStartup(StartupEventArgs e)
if (CurrentProgramVersion == "v0.0.0")
{
logger.Fatal(CultureInfo.InvariantCulture, "Program version not found");
MessageBox.Show("Program version not found", Messages.FATAL_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("Program version not found", Messages.FatalTitle, MessageBoxButton.OK, MessageBoxImage.Error);
LoggingManager.WriteCrashLog(new ArgumentOutOfRangeException("Program version not found"));
}
else
@@ -81,17 +85,28 @@ protected override void OnStartup(StartupEventArgs e)
RestoreSettings();
Settings.Default.Reload();
logger.Info(CultureInfo.InvariantCulture, "Reloaded default settings");

DispatcherUnhandledException += App_DispatcherUnhandledException;

// Stop the stopwatch
stopwatch.Stop();

// Get the elapsed time in milliseconds
double elapsedTimeMs = stopwatch.Elapsed.TotalMilliseconds;

base.OnStartup(e);
SetRenderingMode(s.RenderingMode);

// Print the elapsed time
logger.Debug($"App ctor Elapsed Time: {elapsedTimeMs} ms");
}

private static void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// Log/inspect the inspection here
logger.Error(e.Exception);
}

private static void SetRenderingMode(string renderingMode)
{
RenderOptions.ProcessRenderMode = renderingMode == "Hardware"
@@ -187,7 +202,9 @@ private static void OnAppRun(SemanticVersion version, IAppTools tools, bool firs
It's also recommended to change the resolution of the overlay if you are using a resolution other than the default set.
Happy Hunting!", "MHF-Z Overlay Installation", MessageBoxButton.OK, MessageBoxImage.Information);
Happy Hunting!", "MHF-Z Overlay Installation",
MessageBoxButton.OK,
MessageBoxImage.Information);
isFirstRun = true;
}
}
@@ -229,7 +246,7 @@ public static async Task UpdateMyApp()
logger.Error(ex);
isClowdSquirrelUpdating = false;
splashScreen.Close(TimeSpan.FromSeconds(0.1));
MessageBox.Show("An error has occurred with the update process, see logs.log for more information", Messages.ERROR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("An error has occurred with the update process, see logs.log for more information", Messages.ErrorTitle, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}

0 comments on commit a640106

Please sign in to comment.