mobilefish

Untitled

Jun 8th, 2021
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Web.Mvc;
  3. using Microsoft.ApplicationInsights;
  4.  
  5. namespace WebApplication10.ErrorHandler //namespace will vary based on your project name
  6. {
  7.     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
  8.     public class AiHandleErrorAttribute : HandleErrorAttribute
  9.     {
  10.         public override void OnException(ExceptionContext filterContext)
  11.         {
  12.             if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
  13.             {
  14.                 //If customError is Off, then AI HTTPModule will report the exception
  15.                 if (filterContext.HttpContext.IsCustomErrorEnabled)
  16.                 {
  17.                     var ai = new TelemetryClient();
  18.                     ai.TrackException(filterContext.Exception);
  19.                 }
  20.             }
  21.             base.OnException(filterContext);
  22.         }
  23.     }
  24. }
RAW Paste Data