feat: print all logged exceptions via Troubleshooting

This commit is contained in:
goat 2021-09-17 04:09:38 +02:00
parent 25a71574cf
commit 59ba3bdd07
No known key found for this signature in database
GPG key ID: F18F057873895461
3 changed files with 16 additions and 5 deletions

View file

@ -19,6 +19,7 @@ using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Hooking.Internal;
using Dalamud.Interface.Internal;
using Dalamud.IoC.Internal;
using Dalamud.Logging.Internal;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Ipc.Internal;
using HarmonyLib;
@ -101,6 +102,8 @@ namespace Dalamud
{
try
{
SerilogEventSink.Instance.LogLine += SerilogOnLogLine;
Service<ServiceContainer>.Set();
// Initialize the process information.
@ -393,6 +396,14 @@ namespace Dalamud
// Log.Verbose($"Process.Handle // {__instance.ProcessName} // {__result:X}");
}
private static void SerilogOnLogLine(object? sender, (string Line, LogEventLevel Level, DateTimeOffset TimeStamp, Exception? Exception) e)
{
if (e.Exception == null)
return;
Troubleshooting.LogException(e.Exception, e.Line);
}
private void ApplyProcessPatch()
{
var harmony = new Harmony("goatcorp.dalamud");

View file

@ -53,7 +53,7 @@ namespace Dalamud.Interface.Internal.Windows
this.autoScroll = configuration.LogAutoScroll;
this.openAtStartup = configuration.LogOpenAtStartup;
SerilogEventSink.Instance.OnLogLine += this.OnLogLine;
SerilogEventSink.Instance.LogLine += this.OnLogLine;
this.Size = new Vector2(500, 400);
this.SizeCondition = ImGuiCond.FirstUseEver;
@ -68,7 +68,7 @@ namespace Dalamud.Interface.Internal.Windows
/// </summary>
public void Dispose()
{
SerilogEventSink.Instance.OnLogLine -= this.OnLogLine;
SerilogEventSink.Instance.LogLine -= this.OnLogLine;
}
/// <summary>
@ -476,7 +476,7 @@ namespace Dalamud.Interface.Internal.Windows
_ => throw new ArgumentOutOfRangeException(level.ToString(), "Invalid LogEventLevel"),
};
private void OnLogLine(object sender, (string Line, LogEventLevel Level, DateTimeOffset Offset) logEvent)
private void OnLogLine(object sender, (string Line, LogEventLevel Level, DateTimeOffset Offset, Exception? Exception) logEvent)
{
this.HandleLogLine(logEvent.Line, logEvent.Level, logEvent.Offset);
}

View file

@ -25,7 +25,7 @@ namespace Dalamud.Logging.Internal
/// <summary>
/// Event on a log line being emitted.
/// </summary>
public event EventHandler<(string Line, LogEventLevel Level, DateTimeOffset TimeStamp)> OnLogLine;
public event EventHandler<(string Line, LogEventLevel Level, DateTimeOffset TimeStamp, Exception? Exception)>? LogLine;
/// <summary>
/// Gets the default instance.
@ -45,7 +45,7 @@ namespace Dalamud.Logging.Internal
message += "\n" + logEvent.Exception;
}
this.OnLogLine?.Invoke(this, (message, logEvent.Level, logEvent.Timestamp));
this.LogLine?.Invoke(this, (message, logEvent.Level, logEvent.Timestamp, logEvent.Exception));
}
}
}