Advertisement
mobilefish

Untitled

Jun 8th, 2021
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement