In my MVC4 app I had a global.asax.cs override of Application_Error(object sender, EventArgs e)
where I could extract the exception
, statusCo
Startup.cs
using Microsoft.AspNet.Builder;
namespace NS
{
public class Startup
{
...
public virtual void Configure(IApplicationBuilder app)
{
...
app.UseExceptionHandler("/Home/Error");
...
}
}
}
HomeController.cs
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging;
namespace NS.Controllers
{
public class HomeController : Controller
{
static ILogger _logger;
public HomeController(ILoggerFactory factory)
{
if (_logger == null)
_logger = factory.Create("Unhandled Error");
}
public IActionResult Error()
{
var feature = HttpContext.Features.Get();
var error = feature?.Error;
_logger.LogError("Oops!", error);
return View("~/Views/Shared/Error.cshtml", error);
}
}
}
project.json
...
"dependencies": {
"Microsoft.AspNet.Diagnostics": "1.0.0",
...
}
...