实施Application Insight到Azure功能应用程序

时间:2017-11-10 15:05:10

标签: azure azure-functions azure-application-insights

任何人都知道任何上帝指南吗?

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

 {   
  "frameworks": {   
   "net46":{   
    "dependencies": {   
     "Microsoft.ApplicationInsights": "2.1.0"   
    }   
   }   
   }   
 }
功能应用程序应用程序设置中的

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

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

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

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

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

首先...

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

然后:

telemetry.TrackException(e);

在我的捕获中:

c()

当我尝试保存我的Function应用程序时出现此错误:

  

错误CS1729:'TelemetryConfiguration'不包含带有1个参数的构造函数

2 个答案:

答案 0 :(得分:0)

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

可在此处找到完整文档:https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring

答案 1 :(得分:0)

.Net Core 3.1 Azure功能的@ChrisGillum答案的补充:

如果从Visual Studio中使用Http trigger创建新的Azure函数,则示例中将存在以下行:

log.LogInformation("C# HTTP trigger function processed a request.");

"APPINSIGHTS_INSTRUMENTATIONKEY"添加到local.settings.json Values

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "<YOUR_GUID>"
  },
}

请注意,密钥必须位于名为APPINSIGHTS_INSTRUMENTATIONKEY的应用程序设置中,并且不能包含其他任何内容。

然后会自动添加日志记录:

enter image description here

关于托管值的完整指南:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring?tabs=cmd#enable-application-insights-integration

相关问题