使用 .NET 4.8 和 Startup.cs 的 API 项目的 Application Insights 示例,配置服务

问题描述 投票:0回答:1

是否有人拥有适用于使用 .NET 4.8 和 Startup.cs、配置服务的项目的 Application Insights。它没有 global.asax。 我们在该项目中使用 .NET 4.8 和 AspNetCore 2.1.7 依赖项。 我尝试在本地执行 SDK,但在 Visual Studio 上看不到 API 请求和遥测。我正在使用 Postman 向 API 发送请求。

我应该在哪里添加仪器密钥?该项目有一个App.Config,它没有Appsettings.json或ApplicationInsights.config。

azure asp.net-core azure-application-insights .net-4.8
1个回答
0
投票

从您的屏幕截图中可以清楚地看出您正在使用

Console Application
App.config

在顶部,它添加了 ASP.NET Core 配置服务

Startup.cs

当您将 .NET Core 配置与 .NET Framework 一起使用时,您需要更改

.csproj
文件中的配置,如本 Doc 中所述。

感谢@Chris F Carroll 的解释。 要将多目标配置到同一项目中,我们需要添加框架和核心应用程序的目标框架。

enter image description here

<TargetFrameworks>netcoreapp6.0;net481</TargetFrameworks>  

MSDoc 中所述,对于要将跟踪记录记录到 Application Insights 的控制台应用程序,您需要安装

Microsoft.ApplicationInsights.WorkerService
NuGet 包。

该项目有一个App.Config,它没有Appsettings.json或ApplicationInsights.config

如果您不想手动添加,可以从Connected Services添加(会生成

ApplicationInsights.config
,您可以使用它来添加Instrumentation Key)

enter image description here

enter image description here

</ApplicationInsights>
文件中的
ApplicationInsights.config
之前添加 Instrumentation Key。

enter image description here

<InstrumentationKey>**********</InstrumentationKey>
© www.soinside.com 2019 - 2024. All rights reserved.