0

I have created http trigger function in .net core 3.1 but i am not able to add telemetry for logging in application insights. I am using startup class and adding package Microsoft.Azure.Functions.Extensions in csproj.

But I am getting this error

An unhandled host error has occurred. [2021-06-17T13:08:55.752Z] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Google.Apis.ShoppingContent.v2_1.ShoppingContentService' while attempting to activate 'ShoppingSamples.Content.GoogleAuth'.

Is there any way i can add logs in application insights in http trigger function?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
shashank shekhar
  • 132
  • 2
  • 15
  • This has nothing to do with telemetry. It complains there's no `ShoppingContentService` registered with the DI middleware. Did you register the type in `Startup.ConfigureServices` ? What does your code look like? – Panagiotis Kanavos Jun 23 '21 at 09:17
  • can u guide me how to do that in startup class or share some link..cant i do without startup class..I only need to add log in application insights – shashank shekhar Jun 23 '21 at 10:15
  • Again, the error *has nothing to do with App Insights*. It complains you forgot to add *your own custom class* with `services.AddTransient`, `AddScoped` or `AddSingleton`. People can't help you if you don't post the code in `ConfigureServices`. – Panagiotis Kanavos Jun 23 '21 at 10:26

1 Answers1

1

If you'd like to make your logs from azure function(.net) be captured by azure application insights, you have to solutions:

one is adding app insights instance to azure function when you creating or created function instance in azure portal(that means codeless), see screenshot below, no other configurations.

enter image description here

Another is adding sdk to the function project, with the sdk you can also send custom telemetry(code-based). Don't forget to add APPINSIGHTS_INSTRUMENTATIONKEY in local.settings.json file when debug in local environment.

enter image description here

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29