zoukankan      html  css  js  c++  java
  • 继承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;
                }
            }
        }
    }
  • 相关阅读:
    AddressFamily 枚举指定 Socket 类的实例可以使用的寻址方案
    在.NET开发中灵活使用TreeView控件
    TreeView初始化,返回节点值的方法(转)收藏
    怎样彻底删除系统服务项(转载)
    SQL Server 返回插入记录的自增编号(转)
    Socut.Data.dll 与AspNetPager.dll使用说明及心得体会 (转载)
    ActionScript最新3D引擎项目(转载)
    XP自动搜索功能修复
    Postgresql 重新安装,数据不丢失
    work with postgis & geoserver
  • 原文地址:https://www.cnblogs.com/ChineseMoonGod/p/5351346.html
Copyright © 2011-2022 走看看