Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patkleef/eeb90abc771e86778897089f3a7b2dcb to your computer and use it in GitHub Desktop.
Save patkleef/eeb90abc771e86778897089f3a7b2dcb to your computer and use it in GitHub Desktop.
Application Insights Blog - ApplicationInsightsAiHandleErrorAttribute.cs
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class AiHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
{
if (filterContext.HttpContext.IsCustomErrorEnabled)
{
var ai = new TelemetryClient();
ai.TrackException(filterContext.Exception);
}
}
base.OnException(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment