gpt4 book ai didi

c# - 应用程序洞察 - 全局最低严重性级别过滤器?

转载 作者:行者123 更新时间:2023-12-02 08:27:33 25 4
gpt4 key购买 nike

是否有一个地方可以设置日志写入的最低严重性?它也应该适用于通过 TelemetryClient.TraceTelemetry 写入的跟踪!有几个问题仅涉及 ILogger...

最佳答案

没有直接的方法。但你可以使用telemetry processor以确定可以记录哪个 SeverityLevel

例如,创建一个实现 ITelemetryProcessor 的类,如下所示:

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

// next will point to the next TelemetryProcessor in the chain.
public MyCustomFilter(ITelemetryProcessor next)
{
this.Next = next;
}

public void Process(ITelemetry item)
{
TraceTelemetry traceTelemetry = item as TraceTelemetry;

if (traceTelemetry != null)
{
//use this line of code to determine which SeverityLevel should be logged. In this example, only SeverityLevel is warning and up can be logged
if (traceTelemetry.SeverityLevel < SeverityLevel.Warning) { return; }
}

this.Next.Process(item);
}
}

然后在Startup.cs中注册它(对于.net core web应用程序):

    public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddApplicationInsightsTelemetry();

//register your custom TelemetryProcessor
services.AddApplicationInsightsTelemetryProcessor<MyCustomFilter>();
}

关于c# - 应用程序洞察 - 全局最低严重性级别过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63713226/

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