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>
<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>
<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>
<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] <%x{auth}> - %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>
<!-- 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] <%x{auth}> - %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>
原文地址: http://www.cnblogs.com/firstyi/archive/2007/08/22/865028.html