无法从 Nuget 为 Azure Function 应用程序安装 ApplicationInsights

Unable to install ApplicationInsights from Nuget for Azure Function app

我正在 .NET Core 6 中处理 Azure Function,但我无法初始化 Application Insights。我尝试安装 `Microsoft.ApplicationInsights.AspNetCore -Version 2.20.0' 但我无法安装并出现异常:

错误:

我试过这个命令:

Install-Package Microsoft.ApplicationInsights.AspNetCore -Version 2.20.0

请检查以下步骤是否有助于解决问题:

  1. 在 Visual Studio - Azure Functions Project Publish Window > 单击 Restore Service dependencies and their settings 图标,然后安装 Microsoft.ApplicationInsights.AspNetCore.

  1. 检查 these options 已在 VS > 工具 > NuGet 数据包管理器中检查。

此外,请检查此 中给出的解决方法。

Application Insights 由 Azure Functions 自动添加。您不应将 Microsoft.ApplicationInsights.AspNetCore 包添加到 Azure Functions 项目,因为这样做可能会出现不兼容问题。相反,如果您想编写自定义遥测,请使用位于 here as shown by the docs and those docs:

Microsoft.Azure.WebJobs.Logging.ApplicationInsights NuGet 包

There is a Functions-specific version of the Application Insights SDK that you can use to send custom telemetry data from your functions to Application Insights: Microsoft.Azure.WebJobs.Logging.ApplicationInsights