有人知道这方面的大神指导吗?
首先,我创建了一个 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/