Azure / Azure/azure-functions-core-tools

Application logs are sent through the Function host, with host.json taking effect, instead of being sent directly to Application Insights

Open
#4,232 0 comments 0 reactions 0 assignees View on GitHub
needs-investigation potential-bug
Dominant language
C#
Stars
1.5k
Forks
498
Avg merge
3d 13h
Merged PRs (30d)
13

Description

### Version

v4.0.6610

### Description

I'm developing an Azure Function app with C#/.NET9 in the isolated worker model.

According to the [docs](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=hostbuilder%2Cwindows#application-insights), it should be possible to send application logs directly to Application Insights instead of relaying them through the Function host.

In `appsettings.json`, I have the following logging configuration:

"Logging": {
"LogLevel": {
"Default": "Information",
"AssetGovernance": "Debug"
}
}

to capture all logs in the `AssetGovernance*` category with "Debug" level or higher.

In `Program.cs`, I configure Application Insights to send application logs directly to Application Insights:

// Configure application
builder.ConfigureFunctionsWebApplication();

// Configure services
builder.Services.AddApplicationInsightsTelemetryWorkerService();
builder.Services.ConfigureFunctionsApplicationInsights();
builder.Services.Configure(options => { });
...

// Configure logging
builder.Logging.Services.Configure(options =>
{
var defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");

if (defaultRule is not null)
{
options.Rules.Remove(defaultRule);
}
});

Now, the problem is that no "Debug" logs are send to Application Insights, unless I also set `logging.logLevel.Function: "Debug"` in `host.json`, which means that logs are actually relayed through the Function host?

How can I send logs directly to Application Insights, so logging filtering is only governed by `appsettings.json` (i.e., `host.json` has no effect)?

### Steps to reproduce

See above

Contributor guide

Open the contributing guide

Research direction

Start with the isolated-worker logging setup in Program.cs and compare it with the Logging section in appsettings.json and logging.logLevel.Function in host.json. Reproduce the missing Debug logs using the configuration shown, then trace whether the Function host or Application Insights provider applies the filter; done means direct Application Insights logging follows appsettings.json without requiring host.json changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.