如何将 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屋!
查看全文