mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 20:24:16 +01:00
fix: add exception handler for unobserved task exceptions
This commit is contained in:
parent
9b39db6940
commit
a92aad4a54
1 changed files with 17 additions and 10 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using EasyHook;
|
using EasyHook;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -25,14 +26,14 @@ namespace Dalamud {
|
||||||
|
|
||||||
// Log any unhandled exception.
|
// Log any unhandled exception.
|
||||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||||
|
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||||
|
|
||||||
using (var dalamud = new Dalamud(info)) {
|
using var dalamud = new Dalamud(info);
|
||||||
Log.Information("Starting a session..");
|
Log.Information("Starting a session..");
|
||||||
|
|
||||||
// Run session
|
// Run session
|
||||||
dalamud.Start();
|
dalamud.Start();
|
||||||
dalamud.WaitForUnload();
|
dalamud.WaitForUnload();
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.Fatal(ex, "Unhandled exception on main thread.");
|
Log.Fatal(ex, "Unhandled exception on main thread.");
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -42,21 +43,21 @@ namespace Dalamud {
|
||||||
Log.CloseAndFlush();
|
Log.CloseAndFlush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger NewLogger(string baseDirectory) {
|
private Logger NewLogger(string baseDirectory) {
|
||||||
var logPath = Path.Combine(baseDirectory, "dalamud.txt");
|
var logPath = Path.Combine(baseDirectory, "dalamud.txt");
|
||||||
|
|
||||||
return new LoggerConfiguration()
|
return new LoggerConfiguration()
|
||||||
.WriteTo.Async(a => a.File(logPath))
|
.WriteTo.Async(a => a.File(logPath))
|
||||||
.WriteTo.EventSink()
|
.WriteTo.EventSink()
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
.MinimumLevel.Verbose()
|
.MinimumLevel.Verbose()
|
||||||
#else
|
#else
|
||||||
.MinimumLevel.Information()
|
.MinimumLevel.Information()
|
||||||
#endif
|
#endif
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs arg) {
|
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs arg) {
|
||||||
switch (arg.ExceptionObject) {
|
switch (arg.ExceptionObject) {
|
||||||
case Exception ex:
|
case Exception ex:
|
||||||
|
|
@ -67,5 +68,11 @@ namespace Dalamud {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
if (!e.Observed)
|
||||||
|
Log.Error(e.Exception, "Unobserved exception in Task.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue