I have an ASP.NET MVC application for which I want to log events. I have already a Log class with all the tools I need, but I have to instantiate and to close it explicitly
If the other suggestions don't work or if you need to do things other than just logging also be aware that you can override the OnActionExecuting method (often in a base class for reuse).
// Custom controller.
public class CustomController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Do whatever here...
}
}
// Home controller.
public class HomeController : CustomController
{
// Action methods here...
}