1. 在web.config或app.config中添加如下配置
web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
</configSections>
<iBATIS>
<logging>
<logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="file-watch"/>
<arg key="configFile" value="log4net.xml" />
</logFactoryAdapter>
</logging>
</iBATIS>
</configuration>
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common"/>
</sectionGroup>
</configSections>
<iBATIS>
<logging>
<logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="file-watch"/>
<arg key="configFile" value="log4net.xml" />
</logFactoryAdapter>
</logging>
</iBATIS>
</configuration>
2. 添加log4net.xml配置文件
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="log.txt"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="log.txt"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="FileAppender"/>
</root>
</log4net>
3. 添加对IBatisNet.Common.Logging.Log4Net.dll和log4net.dll的引用
张志敏所有文章遵循创作共用版权协议,要求署名、非商业 、保持一致。在满足创作共用版权协议的基础上可以转载,但请以超链接形式注明出处。
本博客已经迁移到 GitHub , 围观地址: http://beginor.github.io/
本文转自张志敏博客园博客,原文链接:http://www.cnblogs.com/beginor/archive/2009/03/23/1419860.html,如需转载请自行联系原作者