首页 > 代码库 > ibatis + log4net 配置注意事项

ibatis + log4net 配置注意事项

一 在web.config或app.config中配置

   

<configuration>

  <configSections>

<sectionGroup name="iBATIS">
      <section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
    </sectionGroup>
    <!--iBATIS日志配置直接放在当前文件-->
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

</configSections>
  <appSettings>

 <!--iBATIS日志配置-->
  <iBATIS>
    <logging>
      <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
        <!--不能修改为file 或 file-watch,否则ibatis sql将无法抓取-->
        <arg key="configType" value="http://www.mamicode.com/inline"/>
      </logFactoryAdapter>
    </logging>
  </iBATIS>

<log4net>
    <!--不能放到单独的log4net.config中,否则ibatis sql将无法抓取-->
    <root>
      <!--OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL-->
      <level value ="http://www.mamicode.com/ERROR" />
      <appender-ref ref="LogALL" />
    </root>
    <appender name="LogALL" type="log4net.Appender.RollingFileAppender" >
      <file value="http://www.mamicode.com/Log//" />
      <appendToFile value="http://www.mamicode.com/true" />
      <datePattern value="http://www.mamicode.com/yyyy-MM-dd.LOG" />
      <maxSizeRollBackups value="http://www.mamicode.com/10" />
      <rollingStyle value="http://www.mamicode.com/Date" />
      <maximumFileSize value="http://www.mamicode.com/1MB" />
      <staticLogFileName value="http://www.mamicode.com/false" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="http://www.mamicode.com/%d{yyyy-MM-dd HH:mm:ss} %p %u %c %l %m %n" />
      </layout>
    </appender>
    <logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.LazyLoadList">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.SqlMapSession">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.Common.Transaction.TransactionScope">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataAccess.DaoSession">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
      <level value="http://www.mamicode.com/DEBUG" />
    </logger>
  </log4net>
  <!--iBATIS日志配置-->
</configuration>

 

ibatis + log4net 配置注意事项