我编写了一个小型遥测处理器来过滤掉一些 HTTP 404,这对我的应用程序来说不是问题。我一直在关注Microsoft's doc在此过程中。
我创建了一个实现 ITelemetryProcessor 的新类并设置了构造函数和处理函数。
namespace My_App
{
class WebJobQueuesDependencyFilter : ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
// Link processors to each other in a chain.
public WebJobQueuesDependencyFilter(ITelemetryProcessor next)
{
this.Next = next;
}
public void Process(ITelemetry item)
{
var request = item as RequestTelemetry;
if (request != null &&
request.ResponseCode.Equals("404", StringComparison.OrdinalIgnoreCase))
{
// To filter out an item, just terminate the chain:
return;
}
// Send everything else:
this.Next.Process(item);
}
}
}
我还在我的 ApplicationInsights.config 中的 <TelemetryProcessors>
下添加了一行新行
<Add Type="My_App.WebJobQueuesDependencyFilter, My_App" />
启动程序后,我在 Visual Studio 的 AI 中看到以下记录的消息。
AI: ApplicationInsights configuration file loading failed. Type 'My_App.WebJobQueuesDependencyFilter, My_App' was not found. Type loading was skipped. Monitoring will continue.
我怀疑问题出在配置中的行。微软的文档似乎没有详细说明该行应包含的内容。我根据 MS 示例的猜测是过滤器类的命名空间路径和我的应用程序的命名空间。
最佳答案
您可能忘记将类标记为 public
,因此找不到该类型。将您的遥测处理器更新为公共(public)
:
public class WebJobQueuesDependencyFilter : ITelemetryProcessor
此外,指定类型的正确方法包括遥测处理器的完全限定名称,后跟程序集名称。因此,在您的示例中,程序集名称必须为 My_App
<!-- Fully qualified type name, assembly name: -->
<Add Type="My_App.WebJobQueuesDependencyFilter, My_App" />
希望这有帮助!
关于c# - 自定义遥测处理器未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43909642/