Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

Log Reporting Dashboard for ASP.NET MVC

Rate me:
Please Sign up or sign in to vote.
4.94/5 (60 votes)
23 Aug 2010CPOL12 min read 175.1K   5.6K   193  
Log reporting dashboard for Log4Net, NLog, ELMAH, and ASP.NET Health Monitoring.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;

namespace MvcLoggingDemo.Services
{
    /// <summary>
    /// This class allows an Exception filter to be injected when an MVC action is invoked
    /// </summary>
    public class ErrorHandlingActionInvoker : ControllerActionInvoker
    {
        private readonly IExceptionFilter filter;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filter">The exception filter to inject</param>
        public ErrorHandlingActionInvoker(IExceptionFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            this.filter = filter;
        }

        /// <summary>
        /// This methods returns all of the normal filters used
        /// PLUS it appends our custom filter to the end of the list 
        /// </summary>
        /// <param name="controllerContext">The context of the controller</param>
        /// <param name="actionDescriptor">The action descriptor</param>
        /// <returns>All of the action filters</returns>
        protected override FilterInfo GetFilters(
            ControllerContext controllerContext,
            ActionDescriptor actionDescriptor)
        {
            var filterInfo =
                base.GetFilters(controllerContext,
                actionDescriptor);

            filterInfo.ExceptionFilters.Add(this.filter);

            return filterInfo;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Simbient
Australia Australia
Darren Weir is a senior .NET developer working for Simbient in North Sydney, Australia.

My blog is located at dotnetdarren.wordpress.com

Comments and Discussions