-
Notifications
You must be signed in to change notification settings - Fork 190
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
.NET 7 Isolated: Logs missing from Application Insights / Log Analytics #2059
Comments
I think you're looking for this documentation:
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(); |
Thank you, @gabrielweyer. This worked. This seems like a quite fragile way of doing things, involving:
I hope the Functions team finds a better way to wrap this up without exposing their dependency on the AppInsights SDK... perhaps a settings in their WorkerOptions? |
Ideally, we'd like Application Insights to remove the rule themselves -- it trips up a lot of people (not just Functions users...):
But I don't believe this will happen without a major version bump from that package. We see so many people struggling with this, even with the documentation, templates, etc, that it may be worth creating our own We're trying really hard not to mess with App Insights defaults as that has caused even more chaos in the past. Unfortunately, this default is causing a bit of a support issue as we get so many questions about it. We redirect customers to the App Insights (and Functions) docs that explain this, but it's still not a good experience. BTW -- there are other ways around this filter -- see some of the links above. But we thought the best way was to show how you can remove it altogether, rather than layering more rules on top to achieve the same thing. |
I tried above solution and still don't get anything below "warning". I debugged and noticed that there isn't a single rule ( |
I had a similar issue, and once I moved the ConfigureLogging to the end of the chain, it started working, maybe check that? |
This makes this issue even more ridiculous |
This is so convoluted. It's good and understandable that AppInsights adds Warning level as default because we don't want it to spam too much. And what would be the consequences of removing that filter? Would we start seeing more internal .net core logging information than we want? Then what is the proper way to set up AppInsights and keep all the default log levels as Warnings (as it should be) and have our own logging configured by categories, also considering that we are using isolated model? Do we need everything of this, or is something redundant?
|
Hello.
We are running an isolated Function using the latest packages. This is the list of relevant packages:
Dependency injection configuration looks like this:
The host.json looks like this:
However, logs generated from my code using Logger.LogInformation do not show up. Logs generated with Logger.LogWarning do show up.
There is a lot of disperse information out there about logging in Azure Functions:
Image 1
Image 2
I couldn't find any complete examples.
Could someone please point me to an example of how to configure an Isolate Azure Function so that any Logger.LogInformation shows up in AppInsights and Log Analytics (where Logger is an ILogger obtained via Dependency Injection).
P.S. I already checked that nothing is getting sampled away:
I also checked that the log entries show up in the "Log stream" of the function on the Azure Portal.
The text was updated successfully, but these errors were encountered: