Oct 25, 2019 02:08 PM|bank5|LINK
I was thinking about implementing ELMAH but that's probably going to be overkill for my application. Instead, I would like to simply store the error in my database.
I have the method in my home controller -
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
// Get the details of the exception that occurred
var exceptionFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionFeature != null)
// Get which route the exception occurred at
string path = exceptionFeature.Path;
// Get the exception that occurred
Exception e = exceptionFeature.Error;
And my startup.cs has
if (env.IsDevelopment() || env.IsStaging())
else if (env.IsProduction())
However, I noticed it's not catching all the errors. Like if I try to enter a string that is too long for the database, I get a HTTP 500 error instead of being redirected to the Home View.
Do I need to put everything in Try / Catch blocks in order for it to catch the exceptions and redirect?
Anyway, I'm curious what others prefer to do.