As per the Azure documentation, Functions V2 uses the .NET Core logging filter hierarchy for configuration.
In the following example, an instance of ILogger is injected into the Run method of the function.
[FunctionName("MyFunction")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger logger, ExecutionContext executionContext)
{
logger.LogInformation("I don't want to see this in production!"));
}
When inspecting the ILogger object, each LoggerInformation element has MinLevel of null which seems to log all levels.
In production, I only want to log at the Error level. I would like to be able to configure this using an environment variable but I cannot find any documentation which explains how to achieve this. I have tried adding the following environment variable to no effect:
"logging__logLevel__Default: "Error"
In your function app, select Configuration under Settings, and then select Application settings. If you see a setting named APPINSIGHTS_INSTRUMENTATIONKEY , Application Insights integration is enabled for your function app running in Azure.
To set environment variables when you start a container in the Azure portal, specify them in the Advanced page when you create the container. Under Environment variables, enter NumWords with a value of 5 for the first variable, and enter MinLength with a value of 8 for the second variable.
Azure Functions lets you target a specific version of the runtime on Windows by using the FUNCTIONS_EXTENSION_VERSION application setting in a function app. The function app is kept on the specified major version until you explicitly choose to move to a new version.
And if you want to change the log level in azure portal, please follow this: In Azure portal, navigate to your function app -> in the function app settings, make sure enable the Read/Write, then change log level to trace in the host.json.
You can have the Azure Functions scale controller emit logs to either Application Insights or to Blob storage to better understand the decisions the scale controller is making for your function app. To enable this feature, you add an application setting named SCALE_CONTROLLER_LOGGING_ENABLED to your function app settings.
In Azure portal, navigate to your function app -> in the function app settings, make sure enable the Read/Write, then change log level to trace in the host.json. To further add to @Ivan Yang's excellent answer, you can specify a minimum logging level per function in v2 of Azure Functions.
You can set AZURE_FUNCTIONS_ENVIRONMENT to any value, but three values are supported: Development, Staging, and Production. When AZURE_FUNCTIONS_ENVIRONMENT isn't set, it defaults to Development on a local environment and Production on Azure. This setting should be used instead of ASPNETCORE_ENVIRONMENT to set the runtime environment.
Extending the answer given by Pramod
In the portal, navigate to the Azure Function, goto the Configuration blade and press 'New application setting' :
Name: AzureFunctionsJobHost__logging__logLevel__Default
Value: Error
NB. Don't forget you need to press OK, then also press Save on the Configuration blade.
Looking at the code (1, 2, 3) for azure functions runtime, this appears to be possible. You have to set it as
export AzureFunctionsJobHost__logging__logLevel__default=Error
This works for other host.json
settings too
export AzureFunctionsJobHost__extensions__http__routePrefix=just-another-prefix
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