简体   繁体   中英

How to get app insights working on an azure webjob with .net core 2.x?

I have a webjob with .net core 2.1

I have an instrumentation key on the appsettings.json.

and I have this on the method ConfigureServices in program.cs

        services.AddApplicationInsightsTelemetry();

However, I get this error when the app starts

System.InvalidOperationException: 'Unable to resolve service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' while attempting to activate 'Microsoft.AspNetCore.Hosting.DefaultApplicationInsightsServiceConfigureOptions'.'

I havent been able to find any documentation that can help me with this

You should not have to call services.AddApplicationInsightsTelemetry(); to enable application insights.

See also the relevant warning in the docs (also applies to webjobs):

  • Do not add AddApplicationInsightsTelemetry() to the services collection as it registers services that conflict with services provided by the environment.

This is also mentioned in this issue in which someone has exactly the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM