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="inline"/>
      </logFactoryAdapter>
    </logging>
  </iBATIS>

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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。