-
Notifications
You must be signed in to change notification settings - Fork 848
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
211 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
VirtoCommerce.Platform.Web/App_Start/AiExceptionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.ApplicationInsights; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Http.ExceptionHandling; | ||
|
||
namespace VirtoCommerce.Platform.Web.App_Start | ||
{ | ||
public class AiExceptionHandler : ExceptionHandler | ||
{ | ||
public override void Handle(ExceptionHandlerContext context) | ||
{ | ||
if (context != null && context.Exception != null) | ||
{ | ||
var ai = new TelemetryClient(); | ||
ai.TrackException(context.Exception); | ||
} | ||
base.Handle(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
VirtoCommerce.Platform.Web/Controllers/AiHandleErrorAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.ApplicationInsights; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace VirtoCommerce.Platform.Web.Controllers | ||
{ | ||
/// <summary> | ||
/// If the custom errors configuration is Off, then exceptions will be available for the HTTPModule to collect. | ||
/// However, if it is RemoteOnly (default), or On – then the exception will be cleared and not available for us to automatically collect. | ||
/// You can fix that by adding an attribute derived from HandleErrorAttribute and then registering it as global filter as shown below. | ||
/// </summary> | ||
[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 customError is Off, then AI HTTPModule will report the exception | ||
//if (filterContext.HttpContext.IsCustomErrorEnabled) | ||
//{ | ||
// Note: A single instance of telemetry client is sufficient to track multiple telemetry items. | ||
var ai = new TelemetryClient(); | ||
|
||
var properties = new Dictionary<string, string>(); | ||
if(filterContext.HttpContext!=null) | ||
FillFormProperties(filterContext.HttpContext.Request, properties); | ||
|
||
ai.TrackException(filterContext.Exception, properties); | ||
//} | ||
} | ||
base.OnException(filterContext); | ||
} | ||
|
||
private void FillFormProperties(HttpRequestBase request, Dictionary<string, string> dictionary) | ||
{ | ||
if (request.Form == null) return; | ||
|
||
var items = request.Form.AllKeys.SelectMany(request.Form.GetValues, (k, v) => new { key = k, value = v }); | ||
foreach (var item in items) | ||
{ | ||
dictionary.Add(item.key, item.value); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.