Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.92k stars 440 forks source link

Isolated .NET 8 Host is not respecting Log Level Filters in host.json or App Settings #10277

Closed saksham99del closed 1 month ago

saksham99del commented 1 month ago

Is your question related to a specific version? If so, please specify:

.net 8 isolated runtime version

What language does your question apply to? (e.g. C#, JavaScript, Java, All)

C#

Question

We have recently moved our code from .net 6 to .net 8 isolated runtime environment however we are not able to control our log level using application settings in azure function app like we used to do before upgrading to .net 8. it seems like .net 8 doesn't honour either host.json or app settings logging level filters.We had set our log levels to error however our application is continuously throwing all the information logs and it has resulted in a higher cost for our azure resources.

chocvanstraw commented 1 month ago

I have run across a similar issue. When running locally log levels in host.json are respected. Once I deploy to Azure, functions that I have configured with Warning log levels are sending Information logs to app insights, which is not desirable due to the large volume of logs. My logs are sent using ILogger. Below is what my host.json looks like. Each one that is marked with Warning still sent info logs

image

bhagyshricompany commented 1 month ago

Hi Thanks for info please share the code snippet with all repro steps.Thanks

chocvanstraw commented 1 month ago

One question I had regarding this is when I created the function app (using azure cli) I specified the AI name and AI instrumentation key parameters. This wires up the function app to the specified app insights resource. When I deploy my code to Azure, I'm not specifying the AI connection string anywhere and the logs do end up flowing to AI as expected. Is this a valid setup or should I also specify the connection string in Program.cs where I call AddApplicationInsightsTelemetryWorkerService and ConfigureFunctionsApplicationInsights? I just want to rule out any kind of function app configuration issue

chocvanstraw commented 1 month ago

Here is a screen shot from app insights where you can see the logs coming in at the Information level contrary to the desired Warning level specified in host.json shown above

image

chocvanstraw commented 1 month ago

I think I solved my problem. It seems calling ILogger from within a function can be controlled from azure environment variables using LoggingLogLevelwhen the logs are sent to app insights

bhagyshricompany commented 1 month ago

One question I had regarding this is when I created the function app (using azure cli) I specified the AI name and AI instrumentation key parameters. This wires up the function app to the specified app insights resource. When I deploy my code to Azure, I'm not specifying the AI connection string anywhere and the logs do end up flowing to AI as expected. Is this a valid setup or should I also specify the connection string in Program.cs where I call AddApplicationInsightsTelemetryWorkerService and ConfigureFunctionsApplicationInsights? I just want to rule out any kind of function app configuration issue

.That's valid and documented behavior. If the application insights App Setting is present with a key or connection string, the host will use that information. The flow you're describing in bootstrapping is from the Worker

bhagyshricompany commented 1 month ago

I think I solved my problem. It seems calling ILogger from within a function can be controlled from azure environment variables using LoggingLogLevelwhen the logs are sent to app insights

Yes Thats correct.

chocvanstraw commented 1 month ago

Is this an accurate synopsis? When running locally, host.json controls the log levels of functions while local.settings.json controls the log levels of non-function categories such as custom classes. When running in Azure, and using app insights, Environment variables (what used to be called application settings) controls all log levels. If this is correct does host.json have any role in controlling log levels when running in Azure and using app insights?

microsoft-github-policy-service[bot] commented 1 month ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

If you are not the original author (saksham99del) and believe this issue is not stale, please comment with /bot not-stale and I will not close it.