nHibernate在单元测试期间输出sql日志记录(nHibernate output sql logging during unit testings)

我正在VS2008内部针对nHibernate应用程序运行单元测试,并希望在单元测试期间打开日志记录,这样我就可以看到更多的内容。 我已经复制并粘贴了另一个应用程序的app.config,它成功地将nhibernate信息记录到单元测试app.config中,但仍然没有得到任何输出。

这是我的app.config测试项目:

<log4net> <appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/nhibernate.txt" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="100KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/general.txt" /> <appendToFile value="true" /> <maximumFileSize value="100KB" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="DataLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/data.txt" /> <appendToFile value="true" /> <maximumFileSize value="100KB" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <!-- levels: DEBUG, INFO, WARN, ERROR, FATAL --> <root> <level value="DEBUG"/> <appender-ref ref="GeneralLog" /> </root> <logger name="NHibernate" additivity="false"> <level value="DEBUG"/> <appender-ref ref="NHibernateFileLog"/> </logger> <logger name="Pushable.Data" additivity="false"> <level value="DEBUG"/> <appender-ref ref="DataLog"/> </logger> </log4net>

当我运行测试项目时,不会从log4net的任何地方创建输出。 log4net运行的应用程序是否必须是Web或Windows而不是测试应用程序?

I'm running unit tests from inside VS2008 against a nHibernate application and would like to turn on logging during the unit tests so I can see a bit more of what is going on. I've copied and pasted another application's app.config that successfully logs nhibernate information into the unit tests app.config, but still don't get any output.

Here is my app.config for the testing project:

<log4net> <appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/nhibernate.txt" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="100KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="GeneralLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/general.txt" /> <appendToFile value="true" /> <maximumFileSize value="100KB" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="DataLog" type="log4net.Appender.RollingFileAppender"> <file value="Logs/data.txt" /> <appendToFile value="true" /> <maximumFileSize value="100KB" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n" /> </layout> </appender> <!-- levels: DEBUG, INFO, WARN, ERROR, FATAL --> <root> <level value="DEBUG"/> <appender-ref ref="GeneralLog" /> </root> <logger name="NHibernate" additivity="false"> <level value="DEBUG"/> <appender-ref ref="NHibernateFileLog"/> </logger> <logger name="Pushable.Data" additivity="false"> <level value="DEBUG"/> <appender-ref ref="DataLog"/> </logger> </log4net>

When I run the test project, no output is created anywhere from log4net. Does the application that log4net runs under have to be a web or windows and not a testing application?

最满意答案

在测试初始化​​器中,需要有一个调用:

log4net.Config.XmlConfigurator.Configure();

这将使日志记录很好。

In the Test initializer, there needs to be a call:

log4net.Config.XmlConfigurator.Configure();

This will enable logging just fine.

更多推荐