C# Application Insights开发人员模式在ASP.NET Core 3.1中不起作用
我正在使用ASP.NET Core 3.1应用程序中的应用程序洞察,代码如下C# Application Insights开发人员模式在ASP.NET Core 3.1中不起作用,c#,azure,azure-application-insights,C#,Azure,Azure Application Insights,我正在使用ASP.NET Core 3.1应用程序中的应用程序洞察,代码如下 public void ConfigureServices(IServiceCollection services) { services.AddControllers(); ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);
}
如您所见,我已启用开发人员模式,以确保立即推送遥测数据(而不是等待2-5分钟)。然而,它似乎不起作用
关于如何让它工作有什么想法吗?在启用开发人员模式之前它工作了吗 当您像这样将应用程序洞察注册到DI容器中时
services.AddApplicationInsightsTelemetry()
它自动假定您在appsettings.json文件中有一个带有插入键的json对象
"ApplicationInsights": {
"InstrumentationKey": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
当您将其部署为azure web应用程序时,它会自动为您创建一个配置变量
我建议您将插入密钥显式地传递到应用程序InsightsServiceOptions中,以确保正确加载它
ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
aiOptions.DeveloperMode = true;
services.AddApplicationInsightsTelemetry(aiOptions);
DeveloperMode只是意味着SDK通道不会在内存中缓冲遥测项。常规行为是将遥测数据缓存在内存中,每30秒一次,或者当缓冲区有500个项目时,它们会被推送到后端。开发人员模式只会导致发送每个项目而无需缓冲 遥测将在Azure portal中显示,通常需要3-10分钟(取决于后端/索引等延迟,不受SDK控制)。通过启用开发人员模式,只有SDK级别的缓冲被禁用,导致最大“增益”为30秒。遥测仍然需要几分钟才能显示在门户中
(开发人员模式背后的意图是在本地立即显示数据。例如,Visual Studio本身在调试时显示遥测。对于该开发人员,不需要显式启用。附加调试器会自动启用开发人员模式)否。即使将IKey显式传递给AI服务选项,它也无法工作。顺便说一句,我正在基于Windows的应用程序服务计划中使用.Net Core。将数据推送到Azure中的AI实例需要2分钟以上的时间。我使用的是Nuget软件包的2.14版本