azure - 对 Azure Function App 实现 Application Insight

标签 azure azure-functions azure-application-insights

有人知道这方面的大神指导吗?

首先,我创建了一个 Application Insight 资源并放置:

APPINSIGHTS_INSTRUMENTATIONKEY = "INSTRUMENTATION KEY"

在 Function Apps 应用程序设置中。

我尝试为这样的功能应用程序实现 nuget 包。

创建一个project.json 文件并粘贴:

 {   
  "frameworks": {   
   "net46":{   
    "dependencies": {   
     "Microsoft.ApplicationInsights": "2.1.0"   
    }   
   }   
   }   
 }

它安装了 nuget 包(我可以在日志中看到它,一切顺利)。

之后,我将这些片段放入我的代码中以使用telemetry.TrackException(异常)功能:

首先...

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

然后:

var telemetry = new TelemetryClient(new TelemetryConfiguration("INSTRUMENTATION KEY"));

在我的收获中:

telemetry.TrackException(e);

当我尝试保存我的函数应用程序时,我收到此错误:

error CS1729: 'TelemetryConfiguration' does not contain a constructor that takes 1 arguments

最佳答案

您无需引用 Application Insights 库即可将其与函数一起使用。如果您已经设置了 APPINSIGHTS_INSTRUMENTATIONKEY 应用程序设置,则只需将 ILogger 接口(interface)作为参数添加到您的函数中,它就会自动将日志数据发送到您的 Application Insights实例。

完整文档可以在这里找到:https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring

关于azure - 对 Azure Function App 实现 Application Insight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47225709/

相关文章:

sql-server - 此版本的 SQL Server 不支持已弃用的功能 'DROP INDEX with two-part name'

api - Office365 Sharepoint API 对于联合域失败

powershell - 从 powershell 模块运行应用程序洞察查询

azure - 在应用程序见解中禁用另存为查询

azure - 为 .net 6 Web 应用程序配置 App Insights

html - 如何从 Xamarin Forms 中的 Azure B2C 中删除缩放按钮

azure - 如何指定到网关的路由

azure - V2 Azure Function ServiceBusTrigger 不工作

c# - 是否可以从 .net core 查询表存储?

azure - 在应用程序洞察中,如何查找某个时间点 Web 服务的服务器/实例数量?