When working with Azure Functions and isolated process workers, it is crucial to understand that the Functions host and the isolated process worker maintain separate configurations for log levels and other settings. Configurations made in host.json
for Application Insights will not impact the logging behavior of the worker, and vice versa. To ensure proper logging across both the host and the worker, configurations must be applied at both layers.
Despite these separate configurations, your application will still utilize ILogger
and ILogger<T>
. By default, the Application Insights SDK applies a logging filter that only captures warnings and more severe logs. If you need to capture more detailed logs or modify this behavior, you will need to adjust the filter rule within your service configuration.
Below is a sample code snippet showing how to modify the logging settings in an Azure Functions project using an isolated worker. This example demonstrates removing the default filter rule that limits logging to warnings and above.
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services => {
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.ConfigureLogging(logging =>
{
logging.Services.Configure<LoggerFilterOptions>(options =>
{
LoggerFilterRule defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
== "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
if (defaultRule is not null)
{
options.Rules.Remove(defaultRule);
}
});
})
.Build();
host.Run();
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
To ensure all logging works before deployment you can alter local.settings.json to include APPINSIGHTS_INSTRUMENTATIONKEY
. This key can be found inside Azure Portal > Application Insights > Configure > Properties > INSTRUMENTATION KEY
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"APPINSIGHTS_INSTRUMENTATIONKEY": "{Insert key here}"
}
}
When test locally or within a deployed instance you will be able to see live telemetry data. Azure Portal > Application Insights > Live Metrics
Using this Kusto query we are able to see the logs for Informational and above.
union isfuzzy=true traces
| where message contains "This is my"
| order by timestamp desc
| take 100