gpt4 book ai didi

asp.net-mvc - 如何在 Application Insights for ASP.NET MVC(.NET Full) 中临时停止记录 RequestTrackingTelemetryModule

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

我们如何停止记录特定模块,例如 ASP.NET MVC(.NET Full,而不是 .NET Core)中的 RequestTrackingTelemetryModule

我已尝试删除

<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">

ApplicationInsights.config中,但它引发了我一个奇怪的异常

我正在将 Azure Web App 用于临时环境和实时环境。所以我只想停止在实时环境中记录请求信息,因为它花费太多。

感谢您的帮助!

最佳答案

您可以使用 ITelemetryProcessor,然后按照此 link .

添加一个实现 ITelemetryProcessor 的自定义类:

public class MyTelemetryProcessor : ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }

public MyTelemetryProcessor(ITelemetryProcessor next)
{
this.Next = next;
}

public void Process(ITelemetry telemetry)
{

RequestTelemetry request = telemetry as RequestTelemetry;

if (request != null)
{
return;
}

if (request == null)
{
this.Next.Process(telemetry);
}
}
}

然后在 ApplicationInsights.config 中添加以下内容:

<TelemetryProcessors>
<Add Type="WebApplicationMVC.MyTelemetryProcessor, WebApplicationMVC">
<!-- Set public property -->
</Add>
</TelemetryProcessors>

截图:

enter image description here

它确实过滤掉了应用洞察数据中的所有请求,测试结果如下:

enter image description here

关于asp.net-mvc - 如何在 Application Insights for ASP.NET MVC(.NET Full) 中临时停止记录 RequestTrackingTelemetryModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54706730/

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