Click here to Skip to main content
15,881,380 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 174.1K   5.6K   192  
Log reporting dashboard for Log4Net, NLog, ELMAH, and ASP.NET Health Monitoring.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcLoggingDemo.Models
{

    /// <summary>
    /// This represents a generic log message that can store log information about
    /// any logger implemented. Eg: Log4Net, NLog, Health Monitoring, Elmah
    /// </summary>
    public class LogEvent
    {
        private string _Id = string.Empty;

        /// <summary>
        /// String representation of the event log id
        /// </summary>
        public string Id 
        {
            get
            {
                switch (IdType)
                {
                    case "number":
                        return IdAsInteger.ToString();                        

                    case "guid":
                        return IdAsGuid.ToString();                        

                    default:
                        return _Id;
                }
            }

            set
            {
                _Id = value;
            }
        }

        /// <summary>
        /// Stores the Id of the log event as a GUID 
        /// </summary>
        internal Guid IdAsGuid { get; set; }

        /// <summary>
        /// Stores the Id of the log event as an integer
        /// </summary>
        internal int IdAsInteger { get; set; }

        /// <summary>
        /// Stores the base type of the id 
        /// Valid values are : number, guid, string
        /// </summary>
        internal string IdType { get; set; }

        /// <summary>
        /// The date of the log event
        /// </summary>
        public DateTime LogDate { get; set; }

        /// <summary>
        /// The name of the log provider
        /// Example values are NLog, Log4Net, Elmah, Health Monitoring
        /// </summary>
        public string LoggerProviderName { get; set; }

        /// <summary>
        /// Information about where the error occurred
        /// </summary>
        public string Source { get; set; }

        /// <summary>
        /// The machine where the error occured
        /// </summary>
        public string MachineName { get; set; }

        /// <summary>
        /// The Type name of the class that logged the error
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// The level of the message logged
        /// Valid values are : Debug, Info, Warning, Error, Fatal
        /// </summary>
        public string Level { get; set; }

        /// <summary>
        /// The message that was logged
        /// </summary>
        public string Message { get; set; }                

        /// <summary>
        /// If the message was from an error this value will contain details of the stack trace. 
        /// Otherwise it will be empty
        /// </summary>
        public string StackTrace { get; set; }

        /// <summary>
        /// If the message was from an error this value will contain details of the HTTP Server variables and Cookies. 
        /// Otherwise it will be empty
        /// </summary>
        public string AllXml { get; set; }        
    }
}

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