Last active
February 18, 2020 22:02
-
-
Save hd9/086ab91c02b856449aeb7e7ead4b7a38 to your computer and use it in GitHub Desktop.
Handling exceptions on ASP.NET Core web posting to Application Insights
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
// ********************************************** | |
// Fore more information, visit: | |
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html | |
// ********************************************** | |
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | |
public IActionResult Error() | |
{ | |
// IExceptionHandlerPathFeature requires Microsoft.AspNetCore.Diagnostics | |
// run: dotnet add package Microsoft.AspNetCore.Diagnostics --version 2.2.0 | |
var error = HttpContext.Features.Get<IExceptionHandlerFeature>(); | |
if (error != null) | |
{ | |
_telemetry.TrackException(error.Error); | |
} | |
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment