c# - 自定义遥测处理器未加载

标签 c# azure azure-application-insights

我编写了一个小型遥测处理器来过滤掉一些 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/

相关文章:

C# StreamWriter 在单独的类中

c# - Visual Studio : Given Path Not Supported Error

sql-server - Azure SQL 频繁连接超时

python - Azure Functions for python、结构化日志记录到 Application Insights?

azure - Azure功能监控定价的计算

azure - 是否需要对 Azure Application Insights 进行补充日志记录?

c# - 如何在 ASP.NET Core 中实现复选框列表?

c# - 我如何从通用日期列表中选择不同的(按唯一的月份/年份)?

azure - 将 Base64 编码数据传递给curl 请求 - 错误 : Argument list too long

sql-server - 将 Guid 主键和聚集索引迁移到 INT (Azure SQL)