如何使用NHibernate将SQL调用记录到Visual Studio的控制台? [英] How to log SQL calls with NHibernate to the console of Visual Studio?
本文介绍了如何使用NHibernate将SQL调用记录到Visual Studio的控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于 NHibernate ,我具有以下配置文件:
I have the following configuration file for NHibernate:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Server=.\SQLEXPRESS;Database=mydb;Integrated Security=True;</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
但是SQL不在Visual Studio的输出窗口中显示.是否必须安装 log4net ?还是show_sql
应该单独工作?
But the SQL doesn't show in the output window of Visual Studio. Is it mandatory to install log4net? Or should show_sql
work alone?
推荐答案
要在Visual Studio的输出窗口中显示SQL,请在log4net配置中将log4net配置为使用TraceAppender.这个:
To show the SQL in the output window of Visual Studio, configure log4net to use TraceAppender in your log4net config. This:
<appender name="DebugSQL" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
然后这样:
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="DebugSQL" />
</logger>
我似乎无法在此处正确设置其格式. 参见此链接以获取代码示例
I can't seem to format this correctly here. See this link for code example
这篇关于如何使用NHibernate将SQL调用记录到Visual Studio的控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文