I added ELMAH to my ASP.NET MVC project and all was well. I noticed that exceptions that arise from Ajax.BeginForm (simple ajax form post) do not get logged.
When I make those same exceptions happen by calling the Controller Action directly OR doing a JQUERY $.post() ELMAH catches these exceptions.
Controller .cs
[HttpPost]
[Roles(AcctRoles.ThisRole)]
public ActionResult CreateTicket(TicketCreateViewModel ticketvm)
{
throw new Exception("HEY THIS IS AN AJAX ERROR. TEST.");
return null;
}
View (ELMAH DOES NOT LOG)
@using (Ajax.BeginForm("CreateTicket", "Tickets", null, new AjaxOptions
{
HttpMethod = "POST"
}))
{
<div class="form-horizontal">
Form here
</div>
}
JQUERY (ELMAH DOES LOG)
<button onclick="$.post('@Url.Action("CreateTicket", "Tickets")', '');">TEST EXCEPTION BUTTON</button>
When I use Fiddler or the Chrome Inspector network tab to view the response i see the normal Yellow Screen of death. When I look at the event viewer I see the standard ASP.NET warning entry.
I didn't realize there was a rich text editor on the page sending html. This is an apparent bug with ELMAH as seen here: Elmah not logging exceptions for http post requests in MVC app - if the request contains XML