Click here to Skip to main content
15,896,915 members
Articles / Web Development / HTML

A WPF Template solution using MVVM and Castle Windsor

Rate me:
Please Sign up or sign in to vote.
4.78/5 (11 votes)
18 Nov 2013CPOL5 min read 34.9K   1.2K   19  
A WPF application base solution using Castle Windsor and commonly used utilities.
using System;
using NLog;

namespace CommonUtilities
{
    /// <summary>
    /// This is an NLog wrapper.
    /// </summary>
    public class Log : NLog.Logger
    {
        /// <summary>
        /// The _instance (Singleton)
        /// </summary>
        private static readonly Log _instance = new Log();

        /// <summary>
        /// Initializes a new instance of the <see cref="Log"/> class.
        /// </summary>
        public Log():base()
        {
        }

        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static Logger Instance 
        {
            get 
            {
                return LogManager.GetCurrentClassLogger();
            }
        }

        /// <summary>
        /// Informations the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public static void InfoMessage(string message)
        {
            LogManager.GetCurrentClassLogger().Info(message);
        }

        /// <summary>
        /// Informations the message.
        /// </summary>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The arguments.</param>
        public static void InfoMessage(string messageFormat, params object[] args)
        {
            LogManager.GetCurrentClassLogger().Info(messageFormat, args);
        }

        /// <summary>
        /// Informations the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public static void InfoMessage(string message, Exception exception)
        {
            LogManager.GetCurrentClassLogger().InfoException(message, exception);
        }

        /// <summary>
        /// Warnings the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public static void WarningMessage(string message)
        {
            LogManager.GetCurrentClassLogger().Warn(message);
        }

        /// <summary>
        /// Warnings the message.
        /// </summary>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The arguments.</param>
        public static void WarningMessage(string messageFormat, params object[] args)
        {
            LogManager.GetCurrentClassLogger().Warn(messageFormat, args);
        }

        /// <summary>
        /// Warnings the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public static void WarningMessage(string message, Exception exception)
        {
            LogManager.GetCurrentClassLogger().WarnException(message, exception);
        }

        /// <summary>
        /// Errors the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public static void ErrorMessage(string message)
        {
            LogManager.GetCurrentClassLogger().Error(message);
        }

        /// <summary>
        /// Errors the message.
        /// </summary>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The arguments.</param>
        public static void ErrorMessage(string messageFormat, params object[] args)
        {
            LogManager.GetCurrentClassLogger().Error(messageFormat, args);
        }

        /// <summary>
        /// Errors the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public static void ErrorMessage(string message, Exception exception)
        {
            LogManager.GetCurrentClassLogger().ErrorException(message, exception);
        }

        /// <summary>
        /// Fatals the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public static void FatalMessage(string message)
        {
            LogManager.GetCurrentClassLogger().Fatal(message);
        }

        /// <summary>
        /// Fatals the message.
        /// </summary>
        /// <param name="messageFormat">The message format.</param>
        /// <param name="args">The arguments.</param>
        public static void FatalMessage(string messageFormat, params object[] args)
        {
            LogManager.GetCurrentClassLogger().Fatal(messageFormat, args);
        }

        /// <summary>
        /// Fatals the message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public static void FatalMessage(string message, Exception exception)
        {
            LogManager.GetCurrentClassLogger().FatalException(message, exception);
        }
        
    }
}

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) Scodix
Israel Israel
Project Manager and Application Developer, in a wide variety of business applications. Particularly interested in client/server and Graphical User Interface design using Visual C#.

Specialties: 13 Y'rs in C#, 10 Y'rs experience in C++ Highly experienced in wide technologies, IT projects, military projects etc'.

Comments and Discussions