gpt4 book ai didi

c# - 在哪里添加 Application Insights 的应用程序名称

转载 作者:行者123 更新时间:2023-12-03 00:53:28 25 4
gpt4 key购买 nike

包含所有更新并在 .Net Framework(非 Core)上运行的 Visual Studio 2022

我想使用 Application Insights,这样当我的应用程序引发任何相关错误/事件时,它就会记录到 AppInsights 中。

我从本教程开始 https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net并创建了两个不同的应用程序,并记录了我可以在 Azure App Insights 中看到的事件。

当我查看数据时,我创建的两个应用程序具有相同的 AppID。我找不到任何文档来建议我可以在哪里更改 appId 或任何其他方式来说明事件来源(如果来自应用程序一或应用程序二)。

查看报告和文档后,我不确定是否需要以不同方式配置 Azure App Insights,或者是否可以在应用程序级别更改它?我只想能够记录任何错误,但也有办法确定错误是从哪个应用程序引发的?

编辑

我添加了以下类(class)

public class ReportInitialise : ITelemetryInitializer
{
public void Initialise(ITelemetry telemetry)
{
telemetry.Context.Cloud.RoleName = "Test";
telemetry.Context.Cloud.RoleInstance = "TestInstance";
}
}

编辑2

在 MvcApplication 类中,我将以下内容添加到 Application_Start

TelemetryConfiguration.Active.TelemetryInitializers.Add(new ReportInitialise );

解决了难题的最后一部分

最佳答案

When i view the data it has the same AppID for two applications i created.

这是正确的。它是 Application Insights 资源的 ID。

After viewing the reports and documentation im not sure if i need to configure Azure App Insights differently or if i could change it at app level? I just want to be able to record any errors but also have a way to determine which application the error was raised from?

通常,这是通过检查 cloud_RoleName 属性来完成的。在 Web 应用程序中,这被设置为 Web 应用程序名称。如果需要,您可以使用遥测初始化程序覆盖它。

关于c# - 在哪里添加 Application Insights 的应用程序名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75400617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com