未处理的异常无法登录Appinsights [英] Unhandled exception not to log in appinsights

查看:50
本文介绍了未处理的异常无法登录Appinsights的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net aspx中有一个网站.我有一个HTTP处理程序. 如果存在任何未处理的异常,则HTTP处理程序中的application_error函数将捕获该异常.然后,它还会转到global.ascx中的Application_Error.

I have a website in asp.net aspx. I have an HTTP handler. If there is any Unhandled exception, the application_error function in HTTP handler catches it. Then it also goes to Application_Error in global.ascx.

我已经设置了应用程序Insights.config,以将所有异常记录到Azure App见解中. 我想要的是,某些特定的异常(例如maxURLsize)不应记录在我的Azure应用见解中.

I have set up application insights.config to log all the exception in to Azure App insights. What I want is, some specific exception like maxURLsize, should not be logged in my Azure app insights.

我尝试了以下操作,但无法正常工作. 1. HttpContext.Current.Server.ClearError();在Application_Error函数中 2. System.Diagnostics.Debug.Assert(false);在Http处理程序的application_Error事件中.

I tried below things, but its not working. 1. HttpContext.Current.Server.ClearError(); in Application_Error function 2. System.Diagnostics.Debug.Assert(false); in application_Error event in Http Handler.

推荐答案

您可以使用 ITelemetryProcessor .

如果您知道异常名称(例如maxURLsize),则在自定义遥测处理器类中,可以使用以下代码(也可以根据需要组合其他属性):

If you know the exception name, like maxURLsize, then in your custom telemetry processor class, you can use the code below(you can also combine other properties as per your need):

    public class MyErrorFilter: ITelemetryProcessor
    {
        private ITelemetryProcessor Next { get; set; }
        public MyErrorFilter(ITelemetryProcessor next)
        {
            this.Next = next;
        }
        public void Process(ITelemetry item)
        {           

            var exceptions = item as ExceptionTelemetry;

            if (exceptions != null && (exceptions.Exception.GetType().Name.ToLower() == "maxURLsize".ToLower()))
            {                
                return;
            }

            this.Next.Process(item);
        }
    }

然后按照上述文档进行注册.

then register it as per the doc mentioned above.

这篇关于未处理的异常无法登录Appinsights的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆