- ASP.NET_Mvc3Demo.zip
- MVC3Demo.Bll
- Mvc3Demo.sln
- Mvc3Demo.suo
- Mvc3Demo
- packages
- EntityFramework.4.1.10331.0
- EntityFramework.4.1.10331.0.nupkg
- lib
- EntityFramework.4.2.0.0
- EntityFramework.4.2.0.0.nupkg
- lib
- net40
- jQuery.1.5.1
- Content
- Scripts
- jQuery.1.5.1.nupkg
- jQuery.UI.Combined.1.8.11
- Content
- Content
- themes
- base
- Scripts
- jQuery.UI.Combined.1.8.11.nupkg
- jQuery.Validation.1.8.0
- Content
- Scripts
- jQuery.Validation.1.8.0.nupkg
- jQuery.vsdoc.1.5.1
- Content
- Scripts
- jQuery.vsdoc.1.5.1.nupkg
- Modernizr.1.7
- Content
- Scripts
- Modernizr.1.7.nupkg
- repositories.config
- School_DB.zip
- School.bak
|
using System;
namespace Mvc3Demo.Common
{
/// <summary>
/// This is the base class for loggin purposes.
/// Any class that require to log errors/debug/info, it must be derived from this.
/// </summary>
public abstract class LoggerBase
{
#region Member Variables
/// <summary>
/// Member variable to hold the <see cref="ILog"/> instance.
/// </summary>
private readonly log4net.ILog logger = null;
#endregion
#region Properties
/// <summary>
/// Abstract property which must be overridden by the derived classes.
/// The logger prefix is used to create the logger instance.
/// </summary>
protected abstract System.Type LogPrefix
{
get;
}
#endregion
#region Constructors
private static bool isConfigured = false;
/// <summary>
/// Constructor of the class.
/// </summary>
public LoggerBase()
{
// initiate logging class
if (!isConfigured)
{
log4net.Config.XmlConfigurator.Configure();
isConfigured = true;
}
logger = log4net.LogManager.GetLogger(this.LogPrefix);
}
#endregion
#region Methods
#region Protected Methods
/// <summary>
/// Information level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
protected void LogInfo(string message)
{
if (this.logger.IsInfoEnabled)
{
this.logger.Info(message);
}
}
/// <summary>
/// Information level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
/// <param name="e">The exception that needs to be logged.</param>
protected void LogInfo(string message, Exception e)
{
if (this.logger.IsInfoEnabled)
{
this.logger.Info(message, e);
}
}
/// <summary>
/// Warning level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
protected void LogWarn(string message)
{
if (this.logger.IsWarnEnabled)
{
this.logger.Warn(message);
}
}
/// <summary>
/// Warning level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
/// <param name="e">The exception that needs to be logged.</param>
protected void LogWarn(string message, Exception e)
{
if (this.logger.IsWarnEnabled)
{
this.logger.Warn(message, e);
}
}
/// <summary>
/// Error level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
protected void LogError(string message)
{
if (this.logger.IsErrorEnabled)
{
this.logger.Error(message);
}
}
/// <summary>
/// Error level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged.</param>
/// <param name="e">The exception that needs to be logged.</param>
protected void LogError(string message, Exception e)
{
if (this.logger.IsErrorEnabled)
{
this.logger.Error(message, e);
}
}
/// <summary>
/// Debug level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged</param>
protected void LogDebug(string message)
{
if (this.logger.IsDebugEnabled)
{
this.logger.Debug(message);
}
}
/// <summary>
/// Debug level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged</param>
/// <param name="e">The exception that needs to be logged</param>
protected void LogDebug(string message, Exception e)
{
if (this.logger.IsDebugEnabled)
{
this.logger.Debug(message, e);
}
}
/// <summary>
/// Fatal level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged</param>
protected void LogFatal(string message)
{
if (this.logger.IsFatalEnabled)
{
this.logger.Fatal(message);
}
}
/// <summary>
/// Fatal level messages are logged to the logger.
/// </summary>
/// <param name="message">String that needs to be logged</param>
/// <param name="e">The exception that needs to be logged</param>
protected void LogFatal(string message, Exception e)
{
if (this.logger.IsFatalEnabled)
{
this.logger.Fatal(message, e);
}
}
#endregion
#endregion
}
}
|
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.
In-depth coverage of Microsoft .Net, Cloud and many other cutting-edge Technologies.
-
The Mandelbrot set – someone has called it the thumb-print of God – is one of the most beautiful and remarkable discoveries in the entire history of mathematics. My profile picture is generated with that equation.
You may contact Nirosh for Consultations, Code Reviews and Architecture Guide Workshops via c_nir*o*sh@hotmail.com (Remove * to use)
View Nirosh L.W.C.'s profile on LinkedIn
Other Links