Repository navigation
Expand ActionCache logging beyond resilience/degradation - #15
Merged
Merged
Conversation
Batch 2 introduced the library's first logging (ResilientActionCache's degrade/fail-closed warnings and RedisExpiryService's retry warning) but left the rest of the library silent. Adds Debug-level hit/miss/set/remove/ evict/refresh logging centralized in ResilientActionCache (the seam every backend already flows through), Information-level cache-status logging in the MVC and Minimal API filters, refresh-outcome logging in ActionCacheRefreshProvider, and cache-creation-failure logging in the backend factories (covering the IActionCacheFactory.Create() path even when used outside the filter pipeline). All messages are centralized in a new ActionCacheLog static partial class using [LoggerMessage] source generation, keeping call sites to one line and avoiding allocations when a level is disabled. Existing ad hoc log calls are migrated onto it for consistency. Also fixes a stale CLAUDE.md claim (net9.0 -> net10.0, matching the actual TargetFrameworks).
…esh counts, log-output tests - Replace the per-request Information-level FilterCacheStatus event with two Debug events for the only conditions the cache layer cannot observe: FilterCacheKeyUnavailable (2000) and FilterResultNotCacheable (2001). Hit/set/evict/refresh are logged solely by ResilientActionCache, which logs after the awaited operation succeeds, so no duplicate or premature entries. - Guard the Debug-level logs behind IsEnabled so filter/namespace strings are not computed when Debug is off (the namespace is mutated by route-value attachment, so it cannot be cached at construction). - Count requested refresh keys unconditionally and warn (RefreshNoActionsFound, 3002) when keys are requested but no controller actions match the namespace, instead of reporting "refreshed 0 of 0". - Add CapturingLogger test utility and tests pinning the event ids, levels, and messages of the resilient-cache, refresh-provider, and filter diagnostics. Claude-Session: https://claude.ai/code/session_015V3tf4tRXk7q8Ey7dQbtxZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Batch 2 (#13) introduced the library's first logging —
ResilientActionCache's degrade/fail-closed warnings andRedisExpiryService's retry warning — but everything else (filters, all four backend caches, key building, the refresh provider, the factories) stayed silent. This adds diagnostic logging across the library using the idiomaticMicrosoft.Extensions.Loggingpattern already established in Batch 2, without duplicating hit/miss logic across each backend.ActionCacheLogstatic partial class (src/Common/Diagnostics/) using[LoggerMessage]source generation — one line per call site, allocation-free when a level is disabled,EventIdranges kept collision-free (1xxx cache ops, 2xxx filter-level conditions, 3xxx refresh, 4xxx factory failures, 5xxx Redis expiry retry). Existing ad hocLogWarning/LogErrorcalls migrated onto it for consistency.ResilientActionCache, since it already wraps every operation on every backend reached through the filter pipeline — avoids duplicating logging four times acrossMemoryActionCache/RedisActionCache/SqlServerActionCache/AzureCosmosActionCache. These log only after the inner operation succeeds, and only under anIsEnabledguard so the key/namespace strings aren't built when Debug is off.ResilientActionCacheso there's exactly one log line per outcome, not two.ActionCacheRefreshProvidernow logs which keys were skipped (and why), a per-call refresh summary with an accurate requested-key count, and a Warning when keys were requested but no controller actions matched the namespace at all (previously this silently reported "refreshed 0 of 0").ILoggerFactoryand log creation failures — this means a consumer resolvingIActionCacheFactorydirectly (bypassing the filter pipeline, and thereforeResilientCacheDecorator's resilience wrap) still gets a log line if cache creation itself fails.ActionCacheFactoryBasenow documents that this bypass path is an intentional escape hatch, not a bug — it doesn't get automatic degrade-on-failure, since that wrapping is applied only by the filter factories.CLAUDE.mdclaimednet8.0/net9.0; the csproj actually targetsnet8.0/net10.0. Fixed.No behavioral changes to cache semantics — purely additive logging plus the
ILoggerFactory/ILoggerconstructor parameters needed to wire it up (all DI-resolved automatically, no consumer registration changes required).Test plan
dotnet build src/ActionCache.csprojclean on bothnet8.0andnet10.0dotnet test test/Unit/Unit.csproj— 441/441 passing on both TFMs (existingResilientActionCacheTestsupdated to stubILogger.IsEnabledsince[LoggerMessage]-generated code checks it before logging, unlike the previous rawLogWarning/LogErrorcalls; newCapturingLoggertest utility plus dedicated logging-assertion suites for the resilient cache, refresh provider, and filters pin down event ids/levels/messages as the diagnostic contract)dotnet test test/Integration/Integration.csproj— same pre-existing Redis/SQL Server-dependent failures as thedevelopbaseline in this sandbox (no live infra available); no new failures introduced by this change