mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-04-04 15:16:29 -04:00
Update Logging and Error Handling
- Add Configuration.LoggingEnabled property which gets set as soon as Serilog is configured - Add error handling to InteropFactory
This commit is contained in:
@@ -222,7 +222,6 @@ public class App : Application
|
||||
|
||||
// logging is init'd here
|
||||
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(AppScaffolding.Variety.Chardonnay, config);
|
||||
Program.LoggingEnabled = true;
|
||||
}
|
||||
|
||||
private static void ShowMainWindow(IClassicDesktopStyleApplicationLifetime desktop)
|
||||
|
||||
@@ -12,6 +12,7 @@ using LibationAvalonia.Dialogs;
|
||||
using Avalonia.Threading;
|
||||
using FileManager;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
#nullable enable
|
||||
namespace LibationAvalonia
|
||||
@@ -19,7 +20,6 @@ namespace LibationAvalonia
|
||||
static class Program
|
||||
{
|
||||
private static System.Threading.Lock SetupLock { get; } = new();
|
||||
internal static bool LoggingEnabled { get; set; }
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
@@ -56,7 +56,6 @@ namespace LibationAvalonia
|
||||
// most migrations go in here
|
||||
LibationScaffolding.RunPostConfigMigrations(config);
|
||||
LibationScaffolding.RunPostMigrationScaffolding(Variety.Chardonnay, config);
|
||||
LoggingEnabled = true;
|
||||
|
||||
//Start loading the library before loading the main form
|
||||
App.LibraryTask = Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
||||
@@ -106,7 +105,7 @@ namespace LibationAvalonia
|
||||
try
|
||||
{
|
||||
//Try to log the error message before displaying the crash dialog
|
||||
if (LoggingEnabled)
|
||||
if (Configuration.Instance.LoggingEnabled)
|
||||
Serilog.Log.Logger.Error(exception, "CRASH");
|
||||
else
|
||||
LogErrorWithoutSerilog(exception);
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace LibationFileManager
|
||||
{
|
||||
private IConfigurationRoot? configuration;
|
||||
|
||||
public bool LoggingEnabled { get; private set; }
|
||||
|
||||
public void ConfigureLogging()
|
||||
{
|
||||
//pass explicit assemblies to the ConfigurationReaderOptions
|
||||
@@ -40,7 +42,8 @@ namespace LibationFileManager
|
||||
.Destructure.ByTransforming<LongPath>(lp => lp.Path)
|
||||
.Destructure.With<LogFileFilter>()
|
||||
.CreateLogger();
|
||||
}
|
||||
LoggingEnabled = true;
|
||||
}
|
||||
|
||||
[Description("The importance of a log event")]
|
||||
public LogEventLevel LogLevel
|
||||
|
||||
@@ -65,11 +65,19 @@ namespace LibationFileManager
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
|
||||
|
||||
var configAppAssembly = Assembly.LoadFrom(configApp);
|
||||
var type = typeof(IInteropFunctions);
|
||||
InteropFunctionsType = configAppAssembly
|
||||
.GetTypes()
|
||||
.FirstOrDefault(type.IsAssignableFrom);
|
||||
try
|
||||
{
|
||||
var configAppAssembly = Assembly.LoadFrom(configApp);
|
||||
var type = typeof(IInteropFunctions);
|
||||
InteropFunctionsType = configAppAssembly
|
||||
.GetTypes()
|
||||
.FirstOrDefault(type.IsAssignableFrom);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//None of the interop functions are strictly necessary for Libation to run.
|
||||
Serilog.Log.Logger.Error(e, "Unable to load types from assembly {@configApp}", configApp);
|
||||
}
|
||||
}
|
||||
private static string? getOSConfigApp()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user