-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Milestone
Description
Question
Hi,
I'm currently trying to achieve this goal
- Log
RelationalEventId.CommandExecuted
(20101) with a log level ofDebug
in the default case - Log
RelationalEventId.CommandExecuted
(20101) with a log level ofInfo
in cases when the execution took longer than a certain threshold
With this approach, we want to declutter our logging by limiting logs to levels of at least Info
.
I've managed to configure the warning levels during configuration of the context, but that also fixates the internal log level of the event definition to that level.
I couldn't find a way to change the log level on demand, because all possible extension points or properties I've managed to explore are readonly or internal.
The closest I could get was to
- configure my default log level to Info
- create a facade for the internal
RelationalCommandDiagnosticsLogger
- replace the service for it (
options.ReplaceService<...>()
) when configuring the context - override the two
CommandReaderExecuted
methods in my facade - suppress calling
base.CommandReaderExecuted(...)
whenduration
doesn't exceed the threshold
This will, however, prevent the interceptors from being invoked. That's not ideal and achieves only half of my goal.
What part did I miss?
Thank you!
Your code
Stack traces
Verbose output
EF Core version
9.0.8
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 8.0
Operating system
No response
IDE
No response