【问题标题】:Add Telemetry logs in application insights of httptrigger function in .net core 3.1在.net core 3.1 中httptrigger 功能的应用洞察中添加Telemetry 日志
【发布时间】:2021-09-06 20:06:21
【问题描述】:

我在 .net core 3.1 中创建了 http 触发功能,但我无法添加遥测来登录应用程序洞察力。 我正在使用启动类并在 csproj 中添加包 Microsoft.Azure.Functions.Extensions。

但是我收到了这个错误

发生了未处理的主机错误。 [2021-06-17T13:08:55.752Z] Microsoft.Extensions.DependencyInjection.Abstractions:尝试激活“ShoppingSamples.Content.GoogleAuth”时无法解析“Google.Apis.ShoppingContent.v2_1.ShoppingContentService”类型的服务。

有什么方法可以在 http 触发功能的应用洞察中添加日志?

【问题讨论】:

  • 这与遥测无关。它抱怨没有ShoppingContentService 向 DI 中间件注册。您是否在Startup.ConfigureServices 中注册了类型?你的代码是什么样的?
  • 你能指导我如何在启动课程中做到这一点或分享一些链接..我不能没有启动课程..我只需要添加登录应用程序洞察力
  • 同样,错误与 App Insights 无关。它抱怨您忘记使用services.AddTransientAddScopedAddSingleton 添加您自己的自定义类。如果您不在ConfigureServices 中发布代码,人们将无法帮助您。

标签: .net-core dependency-injection azure-functions azure-http-trigger


【解决方案1】:

如果您想让 azure function(.net) 中的日志被 azure application Insights 捕获,您必须解决方案:

一个是adding app insights instance to azure function,当你在天蓝色门户中创建或创建函数实例时(即无代码),见下面的截图,没有其他配置。

另一个是adding sdk to the function project,您还可以使用 sdk 发送自定义遥测数据(基于代码)。在本地环境调试时不要忘记在local.settings.json文件中添加APPINSIGHTS_INSTRUMENTATIONKEY

【讨论】:

    猜你喜欢
    • 2021-04-23
    • 2022-10-16
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    相关资源
    最近更新 更多