輸出IBatis.net生成的SQL語句到控制檯,可以方便調試。html
若是要想輸出IBatis.net的SQL語句到控制檯,那麼只須要作以下配置便可:app
<configSections> <!-- 輸出IBatis.net執行的SQL語句到控制檯 --> <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>
那麼顯示結果以下:spa
另外,利用log4net,可以很輕易地把SQL語句生成到文件上。.net
只需作以下配置:調試
<configSections> <!-- 輸出IBatis.net執行的SQL語句 --> <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> <!-- 定義輸出的附加信息,大小,輸出到的文件等等 --> <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> <!-- 設置錯誤的級別以及附加信息 --> <root> <level value="DEBUG" /> <appender-ref ref="RollingLogFileAppender" /> <appender-ref ref="ConsoleAppender" /> </root> <!-- 只是打印錯誤信息的級別 --> <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>
在F盤生成文件以下:code
轉載自http://www.cnblogs.com/kissdodog/p/4134395.htmlorm