Hi @Singh, Rahul, I see this is a duplicate post of https://learn.microsoft.com/en-us/answers/questions/1657156/azure-functions-logging-not-working-correctly-in-l so I will redirect this question to your original post.
A community member has associated this post with a similar question:
Azure Functions - Logging not working correctly in local
Only moderators can edit this content.
Azure Functions - Logging not working correctly in local
I have a simple dotnet-isolated
Azure function written in .Net 8 which has 1 Http trigger function. I have another custom database logger which is added to this function to enable database logging.
When I am executing the function, none of the Microsoft related logging are getting filtered and it's logging hundreds of entries in my database. I have already tested my custom logger with a simple console application where the logging filtering works correctly. What's interesteing is apart from my own custom logger, the console logs are also not getting filtered.
This is how my Program.cs
looks:-
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureAppConfiguration((context, builder) =>
{
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("local.settings.json", optional: true);
})
.ConfigureLogging((builder, logging) =>
{
logging.AddConsole();
logging.AddDbLogger(options =>
{
builder.Configuration.GetSection("Database")
.GetSection("Options").Bind(options);
});
})
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
I have added the resp. logging in host.json
file:-
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
},
"logLevel": {
"default": "Information",
"Microsoft": "Error"
},
"Database": {
"logLevel": {
"default": "Error"
}
},
"console": {
"logLevel": {
"default": "Error"
}
}
}
}
Still it shows Log entries in Console
and Database
Is there anything wrong with my host.json
?