From 59ba3bdd07ac64d428168f7151e59a90643431fa Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Fri, 17 Sep 2021 04:09:38 +0200 Subject: [PATCH] feat: print all logged exceptions via Troubleshooting --- Dalamud/Dalamud.cs | 11 +++++++++++ Dalamud/Interface/Internal/Windows/ConsoleWindow.cs | 6 +++--- Dalamud/Logging/Internal/SerilogEventSink.cs | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 2ed930a93..c6553b335 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -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.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"); diff --git a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs index 3d756ca1d..c712c55ff 100644 --- a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs @@ -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 /// public void Dispose() { - SerilogEventSink.Instance.OnLogLine -= this.OnLogLine; + SerilogEventSink.Instance.LogLine -= this.OnLogLine; } /// @@ -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); } diff --git a/Dalamud/Logging/Internal/SerilogEventSink.cs b/Dalamud/Logging/Internal/SerilogEventSink.cs index 518e6edca..eb7c23d10 100644 --- a/Dalamud/Logging/Internal/SerilogEventSink.cs +++ b/Dalamud/Logging/Internal/SerilogEventSink.cs @@ -25,7 +25,7 @@ namespace Dalamud.Logging.Internal /// /// Event on a log line being emitted. /// - public event EventHandler<(string Line, LogEventLevel Level, DateTimeOffset TimeStamp)> OnLogLine; + public event EventHandler<(string Line, LogEventLevel Level, DateTimeOffset TimeStamp, Exception? Exception)>? LogLine; /// /// 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)); } } }