Skip to content

Expand ActionCache logging beyond resilience/degradation - #15

Merged
jzills merged 2 commits into
developfrom
feature/action-cache-logging
Aug 21, 2026
Merged

jzills merged 2 commits into
developfrom
feature/action-cache-logging

Conversation

@jzills

@jzills jzills commented Jul 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Batch 2 (#13) introduced the library's first logging — ResilientActionCache's degrade/fail-closed warnings and RedisExpiryService'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 idiomatic Microsoft.Extensions.Logging pattern already established in Batch 2, without duplicating hit/miss logic across each backend.

  • New ActionCacheLog static partial class (src/Common/Diagnostics/) using [LoggerMessage] source generation — one line per call site, allocation-free when a level is disabled, EventId ranges kept collision-free (1xxx cache ops, 2xxx filter-level conditions, 3xxx refresh, 4xxx factory failures, 5xxx Redis expiry retry). Existing ad hoc LogWarning/LogError calls migrated onto it for consistency.
  • Cache operations: Debug-level hit/miss/set/remove/evict/refresh logging added once in ResilientActionCache, since it already wraps every operation on every backend reached through the filter pipeline — avoids duplicating logging four times across MemoryActionCache/RedisActionCache/SqlServerActionCache/AzureCosmosActionCache. These log only after the inner operation succeeds, and only under an IsEnabled guard so the key/namespace strings aren't built when Debug is off.
  • Filters: rather than an Information-level "cache status" line per request (too chatty — every cached endpoint would log on every hit), filters log at Debug only for the two conditions the cache layer can't observe itself: no cache key could be constructed for the request, or the action's result wasn't cacheable. Hit/set/evict/refresh stay solely in ResilientActionCache so there's exactly one log line per outcome, not two.
  • Refresh provider: ActionCacheRefreshProvider now 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").
  • Factories: all four backend cache factories now take ILoggerFactory and log creation failures — this means a consumer resolving IActionCacheFactory directly (bypassing the filter pipeline, and therefore ResilientCacheDecorator's resilience wrap) still gets a log line if cache creation itself fails. ActionCacheFactoryBase now 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.
  • Drive-by: CLAUDE.md claimed net8.0/net9.0; the csproj actually targets net8.0/net10.0. Fixed.

No behavioral changes to cache semantics — purely additive logging plus the ILoggerFactory/ILogger constructor parameters needed to wire it up (all DI-resolved automatically, no consumer registration changes required).

Test plan

  • dotnet build src/ActionCache.csproj clean on both net8.0 and net10.0
  • dotnet test test/Unit/Unit.csproj — 441/441 passing on both TFMs (existing ResilientActionCacheTests updated to stub ILogger.IsEnabled since [LoggerMessage]-generated code checks it before logging, unlike the previous raw LogWarning/LogError calls; new CapturingLogger test 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 the develop baseline in this sandbox (no live infra available); no new failures introduced by this change

jzills added 2 commits July 9, 2026 16:30
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
@jzills
jzills merged commit 6109584 into develop Aug 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant