Add unhandled error handling and crash logging to chardonnay
This commit is contained in:
parent
9243aa47e7
commit
4df9e5abbf
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using AppScaffolding;
|
using AppScaffolding;
|
||||||
@ -35,6 +34,7 @@ namespace LibationAvalonia
|
|||||||
$"\"{Configuration.ProcessDirectory}\"");
|
$"\"{Configuration.ProcessDirectory}\"");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
AppDomain.CurrentDomain.UnhandledException += (o, e) => LogError(e.ExceptionObject);
|
||||||
|
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// //
|
// //
|
||||||
@ -42,6 +42,8 @@ namespace LibationAvalonia
|
|||||||
// //
|
// //
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
||||||
|
try
|
||||||
|
{
|
||||||
var config = LibationScaffolding.RunPreConfigMigrations();
|
var config = LibationScaffolding.RunPreConfigMigrations();
|
||||||
|
|
||||||
//Start as much work in parallel as possible.
|
//Start as much work in parallel as possible.
|
||||||
@ -50,9 +52,11 @@ namespace LibationAvalonia
|
|||||||
|
|
||||||
if (config.LibationSettingsAreValid)
|
if (config.LibationSettingsAreValid)
|
||||||
{
|
{
|
||||||
if (!RunDbMigrations(config))
|
// most migrations go in here
|
||||||
return;
|
LibationScaffolding.RunPostConfigMigrations(config);
|
||||||
|
LibationScaffolding.RunPostMigrationScaffolding(Variety.Chardonnay, config);
|
||||||
|
|
||||||
|
//Start loading the library before loading the main form
|
||||||
App.LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
App.LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +64,11 @@ namespace LibationAvalonia
|
|||||||
|
|
||||||
classicLifetimeTask.Result.Start(null);
|
classicLifetimeTask.Result.Start(null);
|
||||||
}
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LogError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
@ -67,20 +76,35 @@ namespace LibationAvalonia
|
|||||||
.LogToTrace()
|
.LogToTrace()
|
||||||
.UseReactiveUI();
|
.UseReactiveUI();
|
||||||
|
|
||||||
public static bool RunDbMigrations(Configuration config)
|
private static void LogError(object exceptionObject)
|
||||||
|
{
|
||||||
|
var logError = $"""
|
||||||
|
{DateTime.Now} - Libation Crash
|
||||||
|
OS {Configuration.OS}
|
||||||
|
Version {LibationScaffolding.BuildVersion}
|
||||||
|
ReleaseIdentifier {LibationScaffolding.ReleaseIdentifier}
|
||||||
|
InteropFunctionsType {InteropFactory.InteropFunctionsType}
|
||||||
|
LibationFiles {getConfigValue(c => c.LibationFiles)}
|
||||||
|
Books Folder {getConfigValue(c => c.Books)}
|
||||||
|
=== EXCEPTION ===
|
||||||
|
{exceptionObject}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var crashLog = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "LibationCrash.log");
|
||||||
|
|
||||||
|
using var sw = new StreamWriter(crashLog, true);
|
||||||
|
sw.WriteLine(logError);
|
||||||
|
|
||||||
|
static string getConfigValue(Func<Configuration, string> selector)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// most migrations go in here
|
return selector(Configuration.Instance);
|
||||||
LibationScaffolding.RunPostConfigMigrations(config);
|
|
||||||
LibationScaffolding.RunPostMigrationScaffolding(Variety.Chardonnay, config);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception exDebug)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Serilog.Log.Logger.Debug(exDebug, "Silent failure");
|
return ex.ToString();
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user