- Add the
ExceptionUtility.cs
andErrorHandlerAttribute.cs
- Add the
ErrorHandlerAttribute
to your base controller to start logging errors. Like:
[ErrorHandler]
public class BaseController : Controller
{
// ...
}
Based on the request type, the error is either reported as JSON or a norman HTML response (given a view).
Example view Error.cshtml
:
@model dynamic
<div class="alert alert-danger" role="alert">
<strong>Oops.. an error occured with the message "@Model.error"</strong>
<p>The error has been logged with the ID: <span class="label label-primary">@Model.token</span></p>
</div>
The error logs is found in your project root, under /App_Data/ErrorLogs/
.
- A token is generated for each error, for easy searchability.
- Errors is gathered in a single file for each day, separated by year and month folders.
This code is based of this example.
Great article,
I am new to MVC and i was able to implement this sample but how do i test it?