3

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!

HelloWorld
  • 4,100
  • 11
  • 38
  • 64
  • Hi, did you check the configuration on your App Service? Is AppInsights enabled and the connection string properly set? – Facundo La Rocca Jul 16 '20 at 17:22
  • As stated in the code I read the appInsightsKey successfully its in the Console log... App Insights must be enabled because it worked from local place... but indeed it is enabled! – HelloWorld Jul 16 '20 at 17:25
  • Could it be because locally is no ApplicationInsights.config created? Maybe azure code needs it... I do not remember which process is creating that file maybe when I added any appinsights nuget... – HelloWorld Jul 17 '20 at 08:34
  • @HelloWorld which sdk are you using? – Ivan Yang Jul 17 '20 at 08:55
  • 1
    see my UPDATE answer! :-) – HelloWorld Jul 17 '20 at 09:35
  • at the moment i use the workaround to use the: var telemetryClient = serviceProvider.GetRequiredService(); that instance works on azure logging to appInsights. – HelloWorld Jul 17 '20 at 10:09

0 Answers0