IBatis.Net学习笔记七--日志处理

IBatis.Net中提供了方便的日志处理,可以输出sql语句等调试信息。

常用的有两种:
1、输出到控制台:

  <configSections>
    <sectionGroup name="iBATIS">
      <section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common" />
    </sectionGroup>
  </configSections>

<iBATIS>
    <logging>
      <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.TraceLoggerFA, IBatisNet.Common">
        <arg key="showLogName" value="true" />
        <arg key="showDataTime" value="true" />
        <arg key="level" value="ALL" />
        <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:SSS" />
      </logFactoryAdapter>
    </logging>
  </iBATIS>


2、利用log4net输出到文件:

  <configSections>
    <sectionGroup name="iBATIS">
      <section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

 

  <iBATIS>
    <logging>
      <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
        <arg key="configType" value="inline" />
      </logFactoryAdapter>
    </logging>
  </iBATIS>

 

  <log4net>
    <!-- Define some output appenders -->
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="f:\log.txt" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="2" />
      <param name="MaximumFileSize" value="100KB" />
      <param name="RollingStyle" value="Size" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="Header" value="[Header]\r\n" />
        <param name="Footer" value="[Footer]\r\n" />
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
      </layout>
    </appender>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
      </layout>
    </appender>

    <!-- Set root logger level to ERROR and its appenders -->
    <root>
      <level value="DEBUG" />
      <appender-ref ref="RollingLogFileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>

    <!-- Print only messages of level DEBUG or above in the packages -->
    <logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataMapper.LazyLoadList">
      <level value="DEBUG" />
    </logger>
    <logger name="IBatisNet.DataAccess.DaoSession">
      <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.Configuration.DaoProxy">
      <level value="DEBUG" />
    </logger>
  </log4net>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值