Unhandled exception not to log in appinsights

安稳与你 提交于 2019-12-24 22:49:36

问题


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.

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.

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.


回答1:


You can take use ITelemetryProcessor.

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.



来源:https://stackoverflow.com/questions/56945930/unhandled-exception-not-to-log-in-appinsights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!