feat: serialize last exception for franzbot

This commit is contained in:
goat 2021-08-21 14:31:01 +02:00
parent 1333ea7a72
commit 06b1163a52
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 38 additions and 3 deletions

View file

@ -196,6 +196,7 @@ namespace Dalamud
{
case Exception ex:
Log.Fatal(ex, "Unhandled exception on AppDomain");
Troubleshooting.LogException(ex, "DalamudUnhandled");
var info = "Further information could not be obtained";
if (ex.TargetSite != null && ex.TargetSite.DeclaringType != null)

View file

@ -14,14 +14,39 @@ namespace Dalamud
/// <summary>
/// Class responsible for printing troubleshooting information to the log.
/// </summary>
internal static class Troubleshooting
public static class Troubleshooting
{
/// <summary>
/// Log troubleshooting information to Serilog.
/// Log the last exception in a parseable format to serilog.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
{
try
{
var payload = new ExceptionPayload
{
Context = context,
When = DateTime.Now,
Info = exception.ToString(),
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"LASTEXCEPTION:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print exception.");
}
}
/// <summary>
/// Log troubleshooting information in a parseable format to Serilog.
/// </summary>
/// <param name="dalamud">The <see cref="Dalamud"/> instance to read information from.</param>
/// <param name="isInterfaceLoaded">Whether or not the interface was loaded.</param>
public static void LogTroubleshooting(Dalamud dalamud, bool isInterfaceLoaded)
internal static void LogTroubleshooting(Dalamud dalamud, bool isInterfaceLoaded)
{
try
{
@ -47,6 +72,15 @@ namespace Dalamud
}
}
private class ExceptionPayload
{
public DateTime When { get; set; }
public string Info { get; set; }
public string Context { get; set; }
}
private class TroubleshootingPayload
{
public PluginManifest[] LoadedPlugins { get; set; }