日志操作类

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace InsApp.log4
{
    public class LogUtil
    {
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 构造函数
        /// </summary>
        public LogUtil()
        {
            //Log = log4net.LogManager.GetLogger(this.GetType());
        }

        /// <summary>
        /// 重大错误日志。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="args"></param>
        /// <param name="type">System.Reflection.MethodBase.GetCurrentMethod().DeclaringType</param>
        public static void FATAL(Type type, string message, params object[] args)
        {
            message += "(" + type.FullName + ")";
            if (args != null || args.Length > 0)
                Log.FatalFormat(message, args);
            else
                Log.Fatal(message);
        }

        /// <summary>
        /// 错误日志。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="args"></param>
        /// <param name="type">System.Reflection.MethodBase.GetCurrentMethod().DeclaringType</param>
        public static void ERROR(Type type, string message, params object[] args)
        {
            message += "(" + type.FullName + ")";
            if (args != null || args.Length > 0)
                Log.ErrorFormat(message, args);
            else
                Log.Error(message);
        }

        /// <summary>
        /// 警告日志。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="args"></param>
        /// <param name="type">System.Reflection.MethodBase.GetCurrentMethod().DeclaringType</param>
        public static void WARN(Type type, string message, params object[] args)
        {
            message += "(" + type.FullName + ")";
            if (args != null || args.Length > 0)
                Log.WarnFormat(message, args);
            else
                Log.Warn(message);
        }

        /// <summary>
        /// 提示信息日志。
        /// </summary>
        /// <param name="message"></param>
        /// <param name="args"></param>
        /// <param name="type">System.Reflection.MethodBase.GetCurrentMethod().DeclaringType</param>
        public static void INFO(Type type, string message, params object[] args)
        {
            message += "(" + type.FullName + ")";
            if (args != null || args.Length > 0)
                Log.InfoFormat(message, args);
            else
                Log.Info(message);
        }

        /// <summary>
        /// Debug日志。  建议不使用!
        /// </summary>
        /// <param name="message"></param>
        /// <param name="args"></param>
        /// <param name="type">System.Reflection.MethodBase.GetCurrentMethod().DeclaringType</param>
        public static void DEBUG(Type type, string message, params object[] args)
        {
            message += "(" + type.FullName + ")";
            if (args != null || args.Length > 0)
                Log.DebugFormat(message, args);
            else
                Log.Debug(message);
        }


    }
}

posted @ 2007-05-28 15:28  世之云枭  阅读(243)  评论(0编辑  收藏  举报