From 2bb9e3a77efb16c0d7f0ac5a97b3337f12d170f8 Mon Sep 17 00:00:00 2001 From: Loretta Date: Mon, 13 Jul 2026 07:01:19 +0200 Subject: [PATCH] Improve debug logging with caller context in AcBinaryHubProtocol Diagnostic logging methods now use [CallerMemberName] to pass the actual caller's name to the logger via EventId.Name, ensuring logs reflect the true call site. Log message formats were simplified by removing explicit class prefixes. Comments clarify the rationale, and all internal calls were updated to the new signatures. --- AyCode.Services/SignalRs/AcBinaryHubProtocol.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs b/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs index b33b112..a8a8fcd 100644 --- a/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs +++ b/AyCode.Services/SignalRs/AcBinaryHubProtocol.cs @@ -762,30 +762,32 @@ public class AcBinaryHubProtocol : IHubProtocol [Obsolete("Use ILogger via constructor parameter instead. This property will be removed in a future version.")] public static Action? DiagnosticLogger { get; set; } + // A caller-t EventId.Name-ként adjuk tovább (az AyCode logger onnan veszi a CallerName-et) — enélkül + // ez a wrapper saját magát bélyegzi be (pl. [->LogDiagnostic]) a valódi hívó helyett. Ld. DebugLogArgument. [Conditional("DEBUG")] - private void LogDiagnostic(string message) => _logger?.LogDebug(message); + private void LogDiagnostic(string message, [CallerMemberName] string? caller = null) => _logger?.LogDebug(new EventId(0, caller), message); [Conditional("DEBUG")] - private void LogReadSingleArgument(ReadOnlySequence argSlice, int argLength, Type targetType) + private void LogReadSingleArgument(ReadOnlySequence argSlice, int argLength, Type targetType, [CallerMemberName] string? caller = null) { if (_logger == null || !_logger.IsEnabled(LogLevel.Debug)) return; var segmentCount = 0; foreach (var _ in argSlice) segmentCount++; - _logger.LogDebug("[AcBinaryHubProtocol] ReadSingleArgument: argLength={ArgLength}, isSingleSegment={IsSingleSegment}, segments={SegmentCount}, type={TypeName}", + _logger.LogDebug(new EventId(0, caller), "ReadSingleArgument: argLength={ArgLength}, isSingleSegment={IsSingleSegment}, segments={SegmentCount}, type={TypeName}", argLength, argSlice.IsSingleSegment, segmentCount, targetType.Name); } [Conditional("DEBUG")] - private void LogParseInvocation(string target, IReadOnlyList paramTypes, long remaining) + private void LogParseInvocation(string target, IReadOnlyList paramTypes, long remaining, [CallerMemberName] string? caller = null) { if (_logger == null || !_logger.IsEnabled(LogLevel.Debug)) return; var typeNames = new string[paramTypes.Count]; for (var i = 0; i < paramTypes.Count; i++) typeNames[i] = paramTypes[i].Name; - _logger.LogDebug("[AcBinaryHubProtocol] ParseInvocation target='{Target}'; paramTypes.Count={ParamCount}; types=[{Types}]; remaining={Remaining}", + _logger.LogDebug(new EventId(0, caller), "ParseInvocation target='{Target}'; paramTypes.Count={ParamCount}; types=[{Types}]; remaining={Remaining}", target, paramTypes.Count, string.Join(", ", typeNames), remaining); } @@ -1406,7 +1408,7 @@ public class AcBinaryHubProtocol : IHubProtocol { var count = (int)ReadVarUInt(ref r); - LogDiagnostic($"[AcBinaryHubProtocol] ReadArguments count={count}; remaining={r.Remaining}"); + LogDiagnostic($"ReadArguments count={count}; remaining={r.Remaining}"); var args = new object?[count]; @@ -1414,7 +1416,7 @@ public class AcBinaryHubProtocol : IHubProtocol { var targetType = i < paramTypes.Count ? paramTypes[i] : typeof(object); - LogDiagnostic($"[AcBinaryHubProtocol] arg[{i}] targetType={targetType.Name}; remaining={r.Remaining}"); + LogDiagnostic($"arg[{i}] targetType={targetType.Name}; remaining={r.Remaining}"); args[i] = ReadSingleArgument(ref r, targetType, headerContext); OnArgumentRead(args[i], i);