Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override logging settings when running azure Functions locally?

Logging settings for Azure Functions are defined in the host.json file. Currently the run-time filters-out most of the logging categories, so exclusions need to be added to the host.json file. But this file is applied in all environments which results in a single logging configuration for all of them.

How to keep a single definition for production environment in host.json, then to override it when running locally without editing that file every time?

In ASP.Net Core, we use the appsettings.json and appsettings.{environment}.json file to achieve this aim but those are not supported out of the box by Azure Functions.
The equivalent of appsettings.Development.json file for Azure Functions is local.settings.json, but it does not support any configuration related to logging. The Host node it contains is not related in any way to host.json file content.

I also haven't found any easy way to do it programmatically from FunctionsStartup without breaking all/some of Azure Functions DI setup...

like image 429
GGirard Avatar asked Oct 31 '25 12:10

GGirard


1 Answers

There is a way to load in and customize host.json files via environment variables (local.settings.json locally or application settings in the cloud). We just don't yet document it very good. You can see details in this comment:

https://github.com/Azure/azure-functions-host/issues/4575#issuecomment-511570111

For example if I wanted to set an environment variable to change the routePrefix, the host.json would look like

{
    "extensions": {
        "http": {
            "routePrefix": "test",
        }
    }
}

But I could do this with an environment variable with the following format:

AzureFunctionsJobHost__extensions__http__routePrefix with the value of test

I made a note to add official docs on this

like image 124
jeffhollan Avatar answered Nov 04 '25 21:11

jeffhollan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!