继承log4.net的类

Posted ChineseMoonGod

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了继承log4.net的类相关的知识,希望对你有一定的参考价值。

using System;
using System.Diagnostics;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Hbl.Core
{
    public static class Log
    {

        /// <summary>
        /// 一般错误
        /// </summary>
        /// <param name="message">消息</param>
        public static void Error(object message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Error(message);
           
        }

        /// <summary>
        /// 一般错误
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="exception">异常</param>
        public static void Error(object message, Exception exception)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Error(message, exception);
        }


        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="message">消息</param>
        public static void Info(object message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Info(message);
        }

        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="exception">异常</param>
        public static void Info(object message, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Info(message, ex);
        }

        /// <summary>
        /// 警告
        /// </summary>
        /// <param name="message">消息</param>
        public static void Warn(object message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Warn(message);
        }

        /// <summary>
        /// 警告
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="exception">异常</param>
        public static void Warn(object message, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Warn(message, ex);
        }

        /// <summary>
        /// 调试
        /// </summary>
        /// <param name="message">消息</param>
        public static void Debug(object message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Debug(message);
        }

        /// <summary>
        /// 调试
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="exception">异常</param>
        public static void Debug(object message, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(GetCurrentMethodFullName());
            log.Debug(message, ex);
        }

        static string GetCurrentMethodFullName()
        {
            try
            {
                int depth = 2;
                StackTrace st = new StackTrace();
                int maxFrames = st.GetFrames().Length;
                StackFrame sf;
                string methodName, className;
                Type classType;
                do
                {
                    sf = st.GetFrame(depth++);
                    classType = sf.GetMethod().DeclaringType;
                    className = classType.ToString();
                } while (className.EndsWith("Exception") && depth < maxFrames);
                methodName = sf.GetMethod().Name;
                return className + "." + methodName;
            }
            catch
            {
                return null;
            }
        }
    }
}

 

以上是关于继承log4.net的类的主要内容,如果未能解决你的问题,请参考以下文章

扩展片段的类中的选项卡

Android - 试图实例化一个不是片段的类

#yyds干货盘点# C#中的类继承

创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)减速(车速自减)修改车牌号,查询车的载重量。 编写两个构造方法:一个没有(代码片段

java 代码片段

关于JavaScript的类的继承