首页 > Web开发 > 详细

Log4Net 的简要配置

时间:2016-01-15 12:53:44      阅读:156      评论:0      收藏:0      [点我收藏+]
  1. 引用log4net.dll
  2. AssemblyInfo.cs中

    

[assembly: AssemblyVersion("1.0.0.0")]

[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.DOMConfigurator(ConfigFileExtension = "config", Watch = true)]

  3.App.config

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>
  <log4net>
    <!--错误日志配置-->
    <appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Log\\LogError\\"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="100"/>
      <param name="MaxFileSize" value="10240"/>
      <param name="StaticLogFileName" value="false"/>
      <param name="DatePattern" value="yyyyMMdd"/>
      <param name="RollingStyle" value="Date"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%n异常时间:%d [%t] %n异常级别:%-5p %n异 常 类:%c [%x] %n%m %n "/>
      </layout>
    </appender>

    <!--信息日志配置-->
    <appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Log\\LogInfo\\"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxFileSize" value="10240"/>
      <param name="MaxSizeRollBackups" value="100"/>
      <param name="StaticLogFileName" value="false"/>
      <param name="DatePattern" value="yyyyMMdd"/>
      <param name="RollingStyle" value="Date"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%nLogDateTime:%d [%t] %nLogLevel:%-5p %nLogType:%c [%x] %n%m %n"/>
      </layout>
    </appender>
    <!--控制台-->
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline"/>
      </layout>
    </appender>

    <!--log4net.LogManager.GetLogger("logerror")用这个来选择这种类型-->
    <logger name="logerror">
      <level value="ERROR"/>
      <appender-ref ref="ErrorAppender"/>
    </logger>
    <logger name="loginfo">
      <level value="INFO"/>
      <appender-ref ref="InfoAppender"/>
    </logger>
    <!--<root>
      <level value="INFO"/>
      <appender-ref ref="InfoAppender"/>
      <appender-ref ref="ConsoleAppender"/>
    </root>-->
  </log4net>

 

  

Log4Net 的简要配置

原文:http://www.cnblogs.com/smartsensor/p/5132843.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!