0
votes

I'm using a Microsoft.Extensions.Hosting.BackgroundService. In the ExecuteAsync method I start the telemetry operation:

using (_telemetryClient.StartOperation<RequestTelemetry>("someOperationName"))
                { [service implementation goes here] }

In the service implementation I use _logger.LogInformation. And I also call other methods of different classes in my service implementation which also log informations.

These entries are not shown in Azure.

Is there a way to automatically show the log entries of all called methods in Azure Application Insights (Performance -> Operations tab)?

Appsettings:

"Logging": {
    "ApplicationInsights": {
        "LogLevel": {
            "Default": "Information"
        }
    },
    "LogLevel": {
        "Default": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
    },
    "AllowedHosts": "*"
},

ConfigureServices:

        services.AddHostedService<Worker>();
        services.AddApplicationInsightsTelemetryWorkerService();

The instrumentation key is set in Azure. I followed these instructions: https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#net-core-30-worker-service-application

1
Not sure what you mean. If you use the ILogger interface to log information and you want that to appear in app insights that is doable. On the other hand, if you want to track method calls you will have to do that manually. using StartOperation for example, like you do already.Peter Bons
The thing is that the Ilogger-logs are NOT shown in application insigths.MatterOfFact
How did you set up the logging, can you share some code? Could also be that the loglevel is not properly set so information messages might not be send to App Insights. Are you using LogInformation?Peter Bons
I've now added the code to my question. Yes, I use "LogInformation"MatterOfFact
@Julida, Glad that it's solved. It may due to the delay of the app insights ingestion server.Ivan Yang

1 Answers

0
votes

I added the post for closing this issue:

As per the code / configuration provided by op, both of them are correct. I also confirmed at my side, it works.

So I guess the issue may due to the delay of the application insights ingestion server.