问题
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