使用log4net记录ibatis.net的SQL动态查询语句

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>

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 >
3. 添加对IBatisNet.Common.Logging.Log4Net.dll和log4net.dll的引用

你可能感兴趣的:(ibatis)