putting some unhandled exception handlers for logging purposes
MODIFY
WalletWasabi.Backend/Program.cs
WalletWasabi.Backend/Program.cs
@@ -27,7 +27,8 @@ namespace WalletWasabi.Backend
try
{
Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt"));
-
+ AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+ TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
var configFilePath = Path.Combine(Global.DataDir, "Config.json");
var config = new Config(configFilePath);
await config.LoadOrCreateDefaultFileAsync();
@@ -95,6 +96,16 @@ namespace WalletWasabi.Backend
}
}
+ static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
+ {
+ Logger.LogWarning(e?.Exception, "UnobservedTaskException");
+ }
+
+ static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
+ }
+
private static void Coordinator_CoinJoinBroadcasted(object sender, Transaction tx)
{
try

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -73,14 +73,12 @@ namespace WalletWasabi.Gui
static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
- var message = e.Exception!=null ? e.Exception.Message : "CurrentDomain_UnhandledException";
- Logger.LogWarning<Program>(message);
+ Logger.LogWarning(e?.Exception, "UnobservedTaskException");
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
- var message = e.ExceptionObject is Exception ? ((Exception)e.ExceptionObject).Message : "CurrentDomain_UnhandledException";
- Logger.LogWarning<Program>(message);
+ Logger.LogWarning(e?.ExceptionObject as Exception, "UnhandledException");
}
private static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure<App>().UsePlatformDetect().UseReactiveUI();

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -236,17 +236,22 @@ namespace WalletWasabi.Logging
private static void Log(Exception ex, LogLevel level, string category = "")
{
- Log(level, ex.ToString(), category);
+ Log(level, ExceptionToStringHandleNull(ex), category);
}
private static void Log<T>(Exception ex, LogLevel level)
{
- Log<T>(level, ex.ToString());
+ Log<T>(level, ExceptionToStringHandleNull(ex));
}
private static void Log(Exception ex, LogLevel level, Type category = null)
{
- Log(level, ex.ToString(), category);
+ Log(level, ExceptionToStringHandleNull(ex) , category);
+ }
+
+ private static string ExceptionToStringHandleNull(Exception ex)
+ {
+ return ex?.ToString() ?? "Exception was null.";
}
#endregion ExceptionLoggingMethods

putting some unhandled exception handlers for logging purposes