refactor(di): migrate Root + Misc to ILogger<T> (DI-4 Slice D)
Slice D shrinks vs the original plan: three of the six files cannot take an ILogger ctor arg without breaking external contracts. Migrated (8 LogProxy sites across 4 files): - Commands: 2 sites (Warning, Error). New ctor takes ILogger<Commands>. - Themes/ThemeRegistry: 1 site (Debug). ILogger<ThemeRegistry>? is optional (default null) so the existing Build-Suite tests that construct `new ThemeRegistry()` parameterless keep working without changes. _logger?.LogDebug guards the call site. - PayloadHandler: 3 sites (Error, Warning, Error). New ctor takes ILogger<PayloadHandler>. ChatLogWindow's two `new PayloadHandler(this)` sites (the direct field and the Lender lambda) now hand a fresh CreateLogger<PayloadHandler>() from the existing _loggerFactory. Not migrated (5 sites stay on Plugin.LogProxy, plan drifts D12-D14): - D12 - Configuration (1 site): IPluginConfiguration, instantiated by Dalamud's Interface.GetPluginConfig() via reflection on the parameterless ctor. Adding an ILogger arg would break GetPluginConfig. - D13 - Message (4 sites): partial data class with two ctor overloads, mass-instantiated across 3 plugin sites plus Newtonsoft JSON deserialisation. Ctor extension would be invasive across ~20 call sites with low payoff (data-class logger is unusual). - D14 - FontManager (2 sites): both Plugin.LogProxy calls live in static methods (TryGetHellionFontBytes, AddFontWithFallback) that cannot reach an instance _logger. Same root cause as D8 in GameFunctions. FontManager joins the static-bucket alongside EmoteCache et al.; the ctor + _logger field added mid-Slice-D were rolled back to keep the class clean. Plugin.LogProxy surface after C9 (8 file buckets, ~12 sites total): - 4 originally-static consumers: EmoteCache, AutoTranslate, MemoryUtil, WrapperUtil - 3 cannot-take-ctor-arg consumers: Configuration, Message, FontManager - 1 single-static-method consumer: GameFunctions.TryOpenAdventurerPlate (D8 from Slice B) Smoke 2 is now due.
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
using Dalamud.Game.Command;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HellionChat;
|
||||
|
||||
internal sealed class Commands : IDisposable
|
||||
{
|
||||
private readonly Dictionary<string, CommandWrapper> Registered = [];
|
||||
private readonly ILogger<Commands> _logger;
|
||||
|
||||
public Commands(ILogger<Commands> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -52,7 +59,7 @@ internal sealed class Commands : IDisposable
|
||||
{
|
||||
if (!Registered.TryGetValue(command, out var wrapper))
|
||||
{
|
||||
Plugin.LogProxy.Warning($"Missing registration for command {command}");
|
||||
_logger.LogWarning($"Missing registration for command {command}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +69,7 @@ internal sealed class Commands : IDisposable
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Plugin.LogProxy.Error(ex, $"Error while executing command {command}");
|
||||
_logger.LogError(ex, $"Error while executing command {command}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user