refactor(di): migrate Integrations + IPC layer to ILogger<T> (DI-4 Slice B)

Seven services across Integrations/, Ipc/ and GameFunctions/ shift
from Plugin.LogProxy to Microsoft.Extensions.Logging.ILogger<T>.

Files with live LogProxy sites (10 in total):
- Ipc/ExtraChat (1)
- GameFunctions/Chat (6)
- GameFunctions/GameFunctions (2)
- GameFunctions/KeybindManager (1)

Foundation-touch files (no current sites, ctor takes ILogger<T> as
seed for the v1.5.7-11 Plugin-Integrations wave):
- Integrations/HonorificService (also drops the local IPluginLog
  _log field in favour of ILogger<HonorificService> _logger; the
  three _log.* calls there are migrated as a bonus since the field
  had to change anyway)
- IpcManager
- Ipc/TypingIpc

GameFunctions takes ILoggerFactory as an extra ctor arg so it can
hand a typed logger to its nested Chat and KeybindManager (same
pattern MessageStore + MessageEnumerator use in Slice A).

PluginHostFactory factory lambdas updated for all five Slice B
services that need extra resolves.

Plan drift D8: GameFunctions.TryOpenAdventurerPlate is an internal
static method whose only Warning call cannot reach the instance
_logger. The one site stays on Plugin.LogProxy with an inline note;
promoting it to instance + PayloadHandler.cs:814 call-site update is
a v1.5.1+ cleanup, out of DI-4 Slice B scope.
This commit is contained in:
2026-05-17 09:56:46 +02:00
parent d0be75e79d
commit 7a1bd1babc
8 changed files with 65 additions and 31 deletions
+11 -7
View File
@@ -19,6 +19,7 @@ using HellionChat.Resources;
using HellionChat.Util; using HellionChat.Util;
using InteropGenerator.Runtime; using InteropGenerator.Runtime;
using Lumina.Text.ReadOnly; using Lumina.Text.ReadOnly;
using Microsoft.Extensions.Logging;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.AtkValueType; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.AtkValueType;
namespace HellionChat.GameFunctions; namespace HellionChat.GameFunctions;
@@ -98,9 +99,12 @@ internal sealed unsafe class Chat : IDisposable
private long LastPlayerNameDisplayTypeRefresh; private long LastPlayerNameDisplayTypeRefresh;
private PlayerNameDisplayType CurrentPlayerNameDisplayType = PlayerNameDisplayType.FullName; private PlayerNameDisplayType CurrentPlayerNameDisplayType = PlayerNameDisplayType.FullName;
public Chat(Plugin plugin) private readonly ILogger<Chat> _logger;
public Chat(Plugin plugin, ILogger<Chat> logger)
{ {
Plugin = plugin; Plugin = plugin;
_logger = logger;
Plugin.GameInteropProvider.InitializeFromAttributes(this); Plugin.GameInteropProvider.InitializeFromAttributes(this);
ChatLogRefreshHook?.Enable(); ChatLogRefreshHook?.Enable();
@@ -236,7 +240,7 @@ internal sealed unsafe class Chat : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
Plugin.LogProxy.Error(ex, "Error in chat Activated event"); _logger.LogError(ex, "Error in chat Activated event");
} }
}); });
} }
@@ -266,7 +270,7 @@ internal sealed unsafe class Chat : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
Plugin.LogProxy.Error(ex, "Error in chat Activated event"); _logger.LogError(ex, "Error in chat Activated event");
} }
return 1; // Prevent vanilla chat log from gaining focus return 1; // Prevent vanilla chat log from gaining focus
@@ -299,7 +303,7 @@ internal sealed unsafe class Chat : IDisposable
{ {
playerName = SeString.Parse(agent->TellPlayerName).TextValue; playerName = SeString.Parse(agent->TellPlayerName).TextValue;
worldId = agent->TellWorldId; worldId = agent->TellWorldId;
Plugin.LogProxy.Debug($"Detected tell target '[redacted]'@{worldId}"); _logger.LogDebug($"Detected tell target '[redacted]'@{worldId}");
} }
Plugin.CurrentTab.CurrentChannel = new UsedChannel Plugin.CurrentTab.CurrentChannel = new UsedChannel
@@ -358,7 +362,7 @@ internal sealed unsafe class Chat : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
Plugin.LogProxy.Error(ex, "Error in chat Activated event"); _logger.LogError(ex, "Error in chat Activated event");
} }
} }
@@ -408,7 +412,7 @@ internal sealed unsafe class Chat : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
Plugin.LogProxy.Error(ex, "Error in chat Activated event"); _logger.LogError(ex, "Error in chat Activated event");
} }
} }
@@ -624,7 +628,7 @@ internal sealed unsafe class Chat : IDisposable
if (contentId == 0) if (contentId == 0)
{ {
Plugin.ChatGui.PrintError(Language.Chat_SendTell_Error); Plugin.ChatGui.PrintError(Language.Chat_SendTell_Error);
Plugin.LogProxy.Warning( _logger.LogWarning(
"Tried to send a tell with ContentId being 0, sorry this is an internal error." "Tried to send a tell with ContentId being 0, sorry this is an internal error."
); );
return; return;
+15 -4
View File
@@ -14,6 +14,7 @@ using FFXIVClientStructs.FFXIV.Client.UI.Info;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using Lumina.Excel; using Lumina.Excel;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
using Microsoft.Extensions.Logging;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.AtkValueType; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.AtkValueType;
namespace HellionChat.GameFunctions; namespace HellionChat.GameFunctions;
@@ -37,14 +38,20 @@ internal unsafe class GameFunctions : IDisposable
#endregion #endregion
private Plugin Plugin { get; } private Plugin Plugin { get; }
private readonly ILogger<GameFunctions> _logger;
internal KeybindManager KeybindManager { get; } internal KeybindManager KeybindManager { get; }
internal Chat Chat { get; } internal Chat Chat { get; }
internal GameFunctions(Plugin plugin) internal GameFunctions(
Plugin plugin,
ILogger<GameFunctions> logger,
ILoggerFactory loggerFactory
)
{ {
Plugin = plugin; Plugin = plugin;
KeybindManager = new KeybindManager(plugin); _logger = logger;
Chat = new Chat(Plugin); KeybindManager = new KeybindManager(plugin, loggerFactory.CreateLogger<KeybindManager>());
Chat = new Chat(Plugin, loggerFactory.CreateLogger<Chat>());
Plugin.GameInteropProvider.InitializeFromAttributes(this); Plugin.GameInteropProvider.InitializeFromAttributes(this);
ResolveTextCommandPlaceholderHook?.Enable(); ResolveTextCommandPlaceholderHook?.Enable();
@@ -215,6 +222,10 @@ internal unsafe class GameFunctions : IDisposable
} }
catch (Exception e) catch (Exception e)
{ {
// Static method has no instance _logger to reach. Promoting this to
// an instance method would force PayloadHandler.cs:814 (the only
// caller) onto Plugin.Functions.* indirection. Lighter touch for
// DI-4 Slice B is to keep this one site on Plugin.LogProxy.
Plugin.LogProxy.Warning(e, "Unable to open adventurer plate"); Plugin.LogProxy.Warning(e, "Unable to open adventurer plate");
return false; return false;
} }
@@ -255,7 +266,7 @@ internal unsafe class GameFunctions : IDisposable
var byteCount = System.Text.Encoding.UTF8.GetByteCount(ReplacementName); var byteCount = System.Text.Encoding.UTF8.GetByteCount(ReplacementName);
if (byteCount >= PlaceholderBufferSize) if (byteCount >= PlaceholderBufferSize)
{ {
Plugin.LogProxy.Warning( _logger.LogWarning(
$"Replacement name too long for placeholder buffer ({byteCount} bytes >= {PlaceholderBufferSize}); falling back to original." $"Replacement name too long for placeholder buffer ({byteCount} bytes >= {PlaceholderBufferSize}); falling back to original."
); );
ReplacementName = null; ReplacementName = null;
+6 -2
View File
@@ -8,6 +8,7 @@ using FFXIVClientStructs.FFXIV.Client.UI;
using HellionChat.Code; using HellionChat.Code;
using HellionChat.GameFunctions.Types; using HellionChat.GameFunctions.Types;
using HellionChat.Util; using HellionChat.Util;
using Microsoft.Extensions.Logging;
using ModifierFlag = HellionChat.GameFunctions.Types.ModifierFlag; using ModifierFlag = HellionChat.GameFunctions.Types.ModifierFlag;
namespace HellionChat.GameFunctions; namespace HellionChat.GameFunctions;
@@ -306,9 +307,12 @@ internal unsafe class KeybindManager : IDisposable
// VirtualKey.OEM_CLEAR, // VirtualKey.OEM_CLEAR,
}; };
internal KeybindManager(Plugin plugin) private readonly ILogger<KeybindManager> _logger;
internal KeybindManager(Plugin plugin, ILogger<KeybindManager> logger)
{ {
Plugin = plugin; Plugin = plugin;
_logger = logger;
Plugin.GameInteropProvider.InitializeFromAttributes(this); Plugin.GameInteropProvider.InitializeFromAttributes(this);
// Handle keybinds from the game on every tick. // Handle keybinds from the game on every tick.
@@ -507,7 +511,7 @@ internal unsafe class KeybindManager : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
Plugin.LogProxy.Error(ex, "Error in chat Activated event"); _logger.LogError(ex, "Error in chat Activated event");
} }
} }
+7 -6
View File
@@ -2,6 +2,7 @@ using System;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace HellionChat.Integrations; namespace HellionChat.Integrations;
@@ -23,7 +24,7 @@ internal sealed class HonorificService : IDisposable
private readonly ICallGateSubscriber<object> _ready; private readonly ICallGateSubscriber<object> _ready;
private readonly ICallGateSubscriber<object> _disposing; private readonly ICallGateSubscriber<object> _disposing;
private readonly IPluginLog _log; private readonly ILogger<HonorificService> _logger;
private readonly IFramework _framework; private readonly IFramework _framework;
private bool _versionWarningLogged; private bool _versionWarningLogged;
@@ -34,12 +35,12 @@ internal sealed class HonorificService : IDisposable
public HonorificService( public HonorificService(
IDalamudPluginInterface pluginInterface, IDalamudPluginInterface pluginInterface,
IPluginLog log, ILogger<HonorificService> logger,
IFramework framework IFramework framework
) )
{ {
_framework = framework; _framework = framework;
_log = log; _logger = logger;
// Gate objects are cached per-name by Dalamud and safe to register // Gate objects are cached per-name by Dalamud and safe to register
// before Honorific loads — they just won't fire until it does. // before Honorific loads — they just won't fire until it does.
@@ -84,7 +85,7 @@ internal sealed class HonorificService : IDisposable
{ {
if (!_versionWarningLogged) if (!_versionWarningLogged)
{ {
_log.Warning( _logger.LogWarning(
"Honorific API version mismatch — expected major 3, " "Honorific API version mismatch — expected major 3, "
+ "found {Major}.{Minor}. Disabling Honorific integration.", + "found {Major}.{Minor}. Disabling Honorific integration.",
version.Item1, version.Item1,
@@ -104,7 +105,7 @@ internal sealed class HonorificService : IDisposable
catch (Exception ex) catch (Exception ex)
{ {
// Honorific not installed or not yet initialised — Ready will retry. // Honorific not installed or not yet initialised — Ready will retry.
_log.Debug(ex, "Honorific not available at HellionChat startup; awaiting Ready."); _logger.LogDebug(ex, "Honorific not available at HellionChat startup; awaiting Ready.");
IsAvailable = false; IsAvailable = false;
CurrentTitle = null; CurrentTitle = null;
} }
@@ -149,7 +150,7 @@ internal sealed class HonorificService : IDisposable
{ {
// Warning not Debug — a silent unsubscribe failure leaks a live // Warning not Debug — a silent unsubscribe failure leaks a live
// subscription across plugin reloads. // subscription across plugin reloads.
_log.Warning( _logger.LogWarning(
ex, ex,
"Honorific unsubscribe failed (likely API break or gate already gone)." "Honorific unsubscribe failed (likely API break or gate already gone)."
); );
+6 -5
View File
@@ -1,9 +1,12 @@
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Microsoft.Extensions.Logging;
namespace HellionChat.Ipc; namespace HellionChat.Ipc;
public sealed class ExtraChat : IDisposable public sealed class ExtraChat : IDisposable
{ {
private readonly ILogger<ExtraChat> _logger;
#pragma warning disable CS0649 // Assigned through IPC #pragma warning disable CS0649 // Assigned through IPC
[Serializable] [Serializable]
private struct OverrideInfo private struct OverrideInfo
@@ -36,8 +39,9 @@ public sealed class ExtraChat : IDisposable
private volatile Dictionary<Guid, string> ChannelNamesInternal = new(); private volatile Dictionary<Guid, string> ChannelNamesInternal = new();
internal IReadOnlyDictionary<Guid, string> ChannelNames => ChannelNamesInternal; internal IReadOnlyDictionary<Guid, string> ChannelNames => ChannelNamesInternal;
internal ExtraChat() internal ExtraChat(ILogger<ExtraChat> logger)
{ {
_logger = logger;
OverrideChannelGate = Plugin.Interface.GetIpcSubscriber<OverrideInfo, object>( OverrideChannelGate = Plugin.Interface.GetIpcSubscriber<OverrideInfo, object>(
"ExtraChat.OverrideChannelColour" "ExtraChat.OverrideChannelColour"
); );
@@ -62,10 +66,7 @@ public sealed class ExtraChat : IDisposable
catch (Exception ex) catch (Exception ex)
{ {
// ExtraChat is optional; IPC failure is normal when the plugin isn't loaded. // ExtraChat is optional; IPC failure is normal when the plugin isn't loaded.
Plugin.LogProxy.Verbose( _logger.LogTrace(ex, "ExtraChat IPC initial state query failed (peer not loaded?)");
ex,
"ExtraChat IPC initial state query failed (peer not loaded?)"
);
} }
} }
+5 -1
View File
@@ -1,5 +1,6 @@
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using HellionChat.Code; using HellionChat.Code;
using Microsoft.Extensions.Logging;
namespace HellionChat.Ipc; namespace HellionChat.Ipc;
@@ -33,9 +34,12 @@ internal sealed class TypingIpc : IDisposable
private ChatInputState LastState; private ChatInputState LastState;
private bool HasState; private bool HasState;
internal TypingIpc(Plugin plugin) private readonly ILogger<TypingIpc> _logger;
internal TypingIpc(Plugin plugin, ILogger<TypingIpc> logger)
{ {
Plugin = plugin; Plugin = plugin;
_logger = logger;
StateQueryGate = Plugin.Interface.GetIpcProvider<ChatInputState>( StateQueryGate = Plugin.Interface.GetIpcProvider<ChatInputState>(
"HellionChat.GetChatInputState" "HellionChat.GetChatInputState"
+5 -1
View File
@@ -1,11 +1,14 @@
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Microsoft.Extensions.Logging;
namespace HellionChat; namespace HellionChat;
internal sealed class IpcManager : IDisposable internal sealed class IpcManager : IDisposable
{ {
private readonly ILogger<IpcManager> _logger;
private ICallGateProvider<string> RegisterGate { get; } private ICallGateProvider<string> RegisterGate { get; }
private ICallGateProvider<string, object?> UnregisterGate { get; } private ICallGateProvider<string, object?> UnregisterGate { get; }
private ICallGateProvider<object?> AvailableGate { get; } private ICallGateProvider<object?> AvailableGate { get; }
@@ -41,8 +44,9 @@ internal sealed class IpcManager : IDisposable
internal List<string> Registered { get; } = []; internal List<string> Registered { get; } = [];
public IpcManager() public IpcManager(ILogger<IpcManager> logger)
{ {
_logger = logger;
RegisterGate = Plugin.Interface.GetIpcProvider<string>("HellionChat.Register"); RegisterGate = Plugin.Interface.GetIpcProvider<string>("HellionChat.Register");
RegisterGate.RegisterFunc(Register); RegisterGate.RegisterFunc(Register);
+10 -5
View File
@@ -100,8 +100,8 @@ internal static class PluginHostFactory
services.AddSingleton(_ => new Commands()); services.AddSingleton(_ => new Commands());
services.AddSingleton(_ => new FontManager()); services.AddSingleton(_ => new FontManager());
services.AddSingleton(_ => new StatusBar()); services.AddSingleton(_ => new StatusBar());
services.AddSingleton(_ => new IpcManager()); services.AddSingleton(sp => new IpcManager(sp.GetRequiredService<ILogger<IpcManager>>()));
services.AddSingleton(_ => new ExtraChat()); services.AddSingleton(sp => new ExtraChat(sp.GetRequiredService<ILogger<ExtraChat>>()));
services.AddSingleton(sp => new ThemeRegistry( services.AddSingleton(sp => new ThemeRegistry(
Path.Combine( Path.Combine(
@@ -111,13 +111,18 @@ internal static class PluginHostFactory
)); ));
services.AddSingleton(sp => new GameFunctions.GameFunctions( services.AddSingleton(sp => new GameFunctions.GameFunctions(
sp.GetRequiredService<Plugin>() sp.GetRequiredService<Plugin>(),
sp.GetRequiredService<ILogger<GameFunctions.GameFunctions>>(),
sp.GetRequiredService<ILoggerFactory>()
));
services.AddSingleton(sp => new TypingIpc(
sp.GetRequiredService<Plugin>(),
sp.GetRequiredService<ILogger<TypingIpc>>()
)); ));
services.AddSingleton(sp => new TypingIpc(sp.GetRequiredService<Plugin>()));
services.AddSingleton(sp => new Integrations.HonorificService( services.AddSingleton(sp => new Integrations.HonorificService(
sp.GetRequiredService<IDalamudPluginInterface>(), sp.GetRequiredService<IDalamudPluginInterface>(),
sp.GetRequiredService<IPluginLog>(), sp.GetRequiredService<ILogger<Integrations.HonorificService>>(),
sp.GetRequiredService<IFramework>() sp.GetRequiredService<IFramework>()
)); ));