日志管理(log4net)封装系统日志组建dll

namespace MyLog4net
{
    public static class Mylog4net
    {
         public enum ErrorLogType
    {
        /// <summary>
        /// 致命的错误日志
        /// </summary>
        FatalLog,
        /// <summary>
        /// 错误的错误日志
        /// </summary>
        ErrorLog
    }


    /// <summary>
    /// 当需要提示时,必须指定日志的类型,一般应用于当系统提示用户怎样操作,
    /// 哪怕是警告类操作,都应该用此类型
    /// </summary>
    public enum NormalLogType
    {
        /// <summary>
        /// 普通操作日志
        /// </summary>
        InfoLog,
        /// <summary>
        /// 警告日志
        /// </summary>
        WarnLog,
        /// <summary>
        /// 调试日志
        /// </summary>
        DebugLog
    }
      /// <summary>
      /// 系统操作日志(info,warm)
      /// </summary>
      /// <param name="modelClassName">操作的类名,</param>
    /// <param name="functionName">功能名</param>
      /// <param name="strInfo">日志信息。</param>
      /// <param name="logtype">日志级别</param>
    public static void Write(string modelClassName, string functionName, string strInfo, NormalLogType logtype)
    {
        log4net.ILog log = log4net.LogManager.GetLogger(modelClassName + "." + functionName);
        switch (logtype)
        {
            case NormalLogType.DebugLog:
                log.Debug(strInfo);
                break;
            case NormalLogType.InfoLog:
                log.Info(strInfo);
                break;
            case NormalLogType.WarnLog:
                log.Warn(strInfo);
                break;
       
        }
   
    }
/// <summary>
/// 写系统操作日志,一般用于Error及Fatal
/// </summary>
/// <param name="modelClassName">组建操作类名</param>
/// <param name="functionName">功能名如:click,register</param>
/// <param name="errorMsg">错误消息</param>
/// <param name="ex">异常</param>
/// <param name="logtype">错误的级别</param>
    public static void Write(string modelClassName, string functionName, string errorMsg,Exception ex, ErrorLogType logtype)
    {
        log4net.ILog log = log4net.LogManager.GetLogger(modelClassName + "." + functionName);
        switch (logtype)
        {
            case ErrorLogType.ErrorLog:
                log.Error(errorMsg,ex);
                break;
            case ErrorLogType.FatalLog:
                log.Fatal(errorMsg, ex);
                break;
      

        }

    }


    }
}

如此配置:如果用%r无法获取正确类。寻求朋友探讨!

你可能感兴趣的:(dll)