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:
Mbucari
2025-11-13 23:12:57 -07:00
parent f29c19beb8
commit d6b232f342
4 changed files with 19 additions and 10 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -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

View File

@@ -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()
{