Umesh Deshmukh
Umesh Deshmukh

Reputation: 91

Unhandled exception not to log in appinsights

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.

Upvotes: 0

Views: 455

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30025

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.

Upvotes: 1

Related Questions