• log4net配置


    App.config中配置

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <log4net>
        <!--定义输出到文件中-->
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <!--定义文件存放位置-->
          <file value="E:log\"/>
          <appendToFile value="true"/>
          <rollingStyle value="Date"/>
          <datePattern value="yyyy\yyyyMM\yyyyMMdd'.txt'"/>
          <staticLogFileName value="false"/>
          <param name="MaxSizeRollBackups" value="100"/>
          <layout type="log4net.Layout.PatternLayout">
            <!--每条日志末尾的文字说明-->
            <!--输出格式-->
            <!--样例:2008-03-26 13:42:32,111 [10] INFO  Log4NetDemo.MainClass [(null)] - info-->
            <conversionPattern value="%newline %n记录时间:%date %n线程ID:[%thread] %n日志级别:  %-5level %n出错类:%logger property: [%property{NDC}] - %n错误描述:%message%newline %n"/>
          </layout>
        </appender>
        <root>
          <level value="ERROR"/>
          <!--文件形式记录日志-->
          <appender-ref ref="RollingLogFileAppender"/>
        </root>
      </log4net>
    </configuration>

    建立日志类

    [assembly: log4net.Config.XmlConfigurator(Watch = true)]
    namespace ServiceTestFrom
    {
        public class LogHelper
        {
            /// <summary>
            /// 输出日志到Log4Net
            /// </summary>
            /// <param name="t"></param>
            /// <param name="ex"></param>
            #region static void WriteLog(Type t, Exception ex)
    
            public static void WriteLog(Type t, Exception ex)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(t);
                log.Error("Error", ex);
            }
    
            #endregion
    
            /// <summary>
            /// 输出日志到Log4Net
            /// </summary>
            /// <param name="t"></param>
            /// <param name="msg"></param>
            #region static void WriteLog(Type t, string msg)
    
            public static void WriteLog(Type t, string msg)
            {
                log4net.ILog log = log4net.LogManager.GetLogger(t);
                log.Error(msg);
            }
    
            #endregion
    
    
        }
    }
    View Code
  • 相关阅读:
    347. 前 K 个高频元素(桶排序、堆排序)
    322. 零钱兑换 && 416. 分割等和子集(0-1背包问题)
    739. 每日温度 && 503. 下一个更大元素 II (单调栈)
    1110. 删点成林
    个人纪录
    pub get failed (server unavailable) -- attempting retry 1 in 1 second?
    python 遍历文件夹重命名
    flutter vscode 连接iphone失败
    部署以太坊合约
    Web漏洞扫描工具AppScan10介绍
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/4414494.html
Copyright © 2020-2023  润新知