Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nlykkei opened this issue Jan 16, 2025 · 0 comments

Comments

@nlykkei
Copy link

nlykkei commented Jan 16, 2025

Version

v4.0.6610

Description

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

According to the docs, 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<WorkerOptions>(options => { });
...

// Configure logging
builder.Logging.Services.Configure<LoggerFilterOptions>(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant