心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  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>

 

  

posted on 2016-01-15 11:41  心澄欲遣  阅读(209)  评论(0编辑  收藏  举报
欢迎第myspace graphics个访客