zoukankan      html  css  js  c++  java
  • Log4net简单使用

    日志记录:

    static log4net.ILog _log = log4net.LogManager.GetLogger
    (System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    _log.Error(exception);
    _log.InfoFormat("test:{0}", s.ToString())

    Log4Net.config:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <!--日志记录组建配置-->
      <log4net>
        <!-- Console部分log输出格式的设定 -->
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger %ndc - %message%newline" />
          </layout>
        </appender>

        <logger name="FileLogger">
          <level value="All" />
          <appender-ref ref="RollingLogFileAppender" />
        </logger>

        <!-- 日志文件部分log输出格式的设定 -->
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="Logs\Log_" />
          <appendToFile value="true" />
          <rollingStyle value="Date" />
          <datePattern value="yyyyMMdd'.txt'" />
          <staticLogFileName value="false" />
          <layout type="log4net.Layout.PatternLayout">
            <header value="------------------------------------------------------------&#xD;&#xA;" />
            <ConversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
          </layout>
        </appender>

        <!-- Setup the root category, add the appenders and set the default level -->
        <root>
          <level value="ALL" />
          <appender-ref ref="ConsoleAppender" />
        </root>
      </log4net>
    </configuration>

    App.config:

    <configSections>
        <section name="log4net"
    type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <log4net>
        <!-- Console部分log输出格式的设定 -->
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%message%newline" />
          </layout>
        </appender>
    
        <!-- 日志文件部分log输出格式的设定 -->
        <appender name="RollingLogFileAppender"
          type="log4net.Appender.RollingFileAppender">
          <file value="Logs\Hosting_" />
          <appendToFile value="true" />
          <rollingStyle value="Date" />
          <datePattern value="yyyyMMdd'.txt'" />
          <staticLogFileName value="false" />
          <layout type="log4net.Layout.PatternLayout">
            <!--<header value="[Header]&#xD;&#xA;" />
            <footer value="[Footer]&#xD;&#xA;" />-->
            <ConversionPattern value="�te - %message%newline" />
          </layout>
        </appender>
    
        <!-- Setup the root category, add the appenders and set the default level -->
        <root>
          <level value="ALL" />
          <appender-ref ref="ConsoleAppender" />
          <appender-ref ref="RollingLogFileAppender" />
        </root>
      </log4net>

    DLL:

    log4net.dll

  • 相关阅读:
    python反射
    numpy笔记
    leetcode43
    leetcode-42
    The Github Flow
    leetcode-37
    leetcode-41
    leetcode-40
    TCP扫盲2
    字节码分析与操作
  • 原文地址:https://www.cnblogs.com/Hacker2012/p/2563934.html
Copyright © 2011-2022 走看看