efcore
efcore copied to clipboard
Disable `Microsoft.Extensions.Logging` logging on a DbContext instance
Having queries and execution times in log is awesome feature, but for some queries it's not that useful and can generate a lot of noise. For example when inserting or updating tons of records, log output is not really useful.
It would be nice if we could disable log on a context instance. For example context.DisableLogging() or something like that.
@domagojmedo What kind of logging are you using?
What do you mean by "kind" of logging? I use Microsoft.Extensions.Logging if that's what you meant
There are a few options for handling this by either adjusting the config or rolling your own: https://stackoverflow.com/questions/42079956/suppress-sql-queries-logging-in-entity-framework-core https://docs.microsoft.com/en-us/dotnet/core/extensions/custom-logging-provider
But obviously that's not the same as one line of code at runtime (global or per action).
Somewhat related I think, I worked around this by tagging queries and filtered based on those (using Serilog).
@davidfenko most issues I have with this is for inserts. I'm don't think you can tag those