Allow response caching cache to log
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is your feature request related to a problem? Please describe.
In reviewing [a PR](https://github.com/dotnet/AspNetCore.Docs/pull/24444#discussion_r777626989) for updates to the ASP.NET Core Output Caching middleware docs, I realised the default limit of 100MB is quite small and we'd likely be hitting that (turns out definitely, we estimate we should have a few GB 😅). I was trying to figure out how we'd know if we were hitting the limit, so dug down through the middleware and into the underlying `MS.Extensions.Caching.Memory.MemoryCache` implementation and found it does log a few Debug level messages saying its cleaning house ("Overcapacity compaction triggered").
So I tried to replicate that log entry locally and couldn't. I believe the issue is that the [ResponseCachingMiddleware ctor](https://github.com/dotnet/aspnetcore/blob/c85baf8db0c72ae8e68643029d514b2e737c9fae/src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs#L39-L54) is spawning its own instance of MemoryCache directly and not giving it a logger, so it gets the no-op logger.
I think this log message could provide value, and I'm discussing on the docs PR about whether we mention that in the docs, so if we give it a logger I think we'll be OK here.
### Describe the solution you'd like
First thought was to pass an instance of `ILogger` to `MemoryCache` ctor, but actually it only accepts a logger factory.
It could be valuable to have another ctor that takes an `ILogger` instance so that, for example in this case, the consumer can pass one with a more specific category like "AspNetCoreResponseCache" (rather than being mixed in with the shared instance).
I'll can whip up a PR with a seal of approval on the approach.
### Additional context
Add any other context or screenshots about the feature request here.
Contributor guide
Assessment
This issue has not been assessed yet.