'ILogger logs to app insights locally but not on azure

The following code work on my machine locally. That means all log statements are in app insights after some minutes...

When I deploy the application with Publish as Webjob all gets deployed BUT there are no log statement of the triggered webjob although I can see it runs every 5 seconds...

I also tried Thread.Sleep(30000); // 30 seconds...

Why does app insights work locally but not hosted on azure?

Console application .NET 4.7.2:

  // Create the DI container.
                IServiceCollection services = new ServiceCollection();
    
                var appInsightsKey = ConfigurationManager.AppSettings.Get("APPINSIGHTS_INSTRUMENTATIONKEY");
                Console.WriteLine($"appInsightsKey: {appInsightsKey}");
    
                // Being a regular console app, there is no appsettings.json or configuration providers enabled by default.
                // Hence instrumentation key and any changes to default logging level must be specified here.
                services.AddLogging(loggingBuilder =>
                {
                    loggingBuilder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
                    loggingBuilder.AddApplicationInsights(appInsightsKey);
                }
                );
    
                services.AddApplicationInsightsTelemetryWorkerService(appInsightsKey);
                IServiceProvider serviceProvider = services.BuildServiceProvider();
                // Obtain logger instance from DI.
                ILogger<Program> logger = serviceProvider.GetRequiredService<ILogger<Program>>();
    
                logger.LogWarning("nogger 2: warning");
                logger.LogInformation("nogger2: information");
                logger.LogError("nogger2: error");
    
                Console.WriteLine("This is the end...");
    
                Task.Delay(5000).Wait();

UPDATE

I am using Microsoft.ApplicationInsights.WorkerService nuget:

https://docs.microsoft.com/de-de/azure/azure-monitor/app/worker-service

scroll down for .NET framework console apps!

I have noticed something interesting (the different display of the references...) but maybe it does not make any difference in the end because with both projects the ILogging in azure does not work:

4.7.2 project:

xx

4.6.1 project:

enter image description here

I have also just deployed as Azure Webjob vom Visual Studio with debug mode and still it does not work and I even configured appinsights extra in that deploy dialog but no difference!



Solution 1:[1]

Have you tried converting it into a continuous web job...? I had similar issues that got resolved upon switching from triggered to continuous web job...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gabba