I have an Azure Function in .net5 (a.k.a. dotnet-isolated) and I've added Entity Framework like this
services.AddDbContext<EfDbContext>(options =>
{
options.UseSqlServer(context.Configuration[...], builder =>
{
builder.EnableRetryOnFailure();
});
});
When I run the function I see the DB queries from EF in the console (info level judging by the color).

How can I disable them? I tried obvious options in my host.json:
"logging": {
"logLevel": {
"Microsoft.EntityFrameworkCore": "Warning",
}
}
and
"logging": {
"logLevel": {
"default": "Information",
"Microsoft.EntityFrameworkCore": "Warning",
"Microsoft.EntityFrameworkCore.Database": "Warning",
"Microsoft.EntityFrameworkCore.Query": "Warning"
}
}
or even
"logging": {
"logLevel": {
"Microsoft": "Warning",
}
}
but it didn't help. The only option which worked was
"logging": {
"logLevel": {
"default": "Warning",
}
}
Am I missing something?
Found a way. That's a bit strange though and I still wanna understand how it works and why it's done this way. Anyways, from AppInsights logs I found out that EF logs are written under the Function.<YOUR_FUNCTION_NAME>.User category. (turns out that a standard EF category is somehow overwritten by the functions runtime or so?).
That means that I can impact on the overall log level of a specific function by
"logging": {
"logLevel": {
"Function.MyFunc1.User": "Debug",
"Function.MyFunc2.User": "Warning"
}
}
in the host.json. It can be helpful but it doesn't solve my problem.
If however I now add a filter in the Program.cs like this:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
...
.ConfigureLogging(builder =>
{
builder.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
})
...
the EF info logs are gone.
This worked for me:
builder.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.None);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With