如何使用NHibernate将SQL调用记录到Visual Studio的控制台?(How to log SQL calls with NHibernate to the console of Vis

编程入门 行业动态 更新时间:2024-10-21 04:02:33
如何使用NHibernate将SQL调用记录到Visual Studio的控制台?(How to log SQL calls with NHibernate to the console of Visual Studio?)

我有以下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单独工作?

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>

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。 这个:

<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>

编辑:我似乎无法正确格式化这里。 有关代码示例,请参阅此链接

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>

Then this:

<logger name="NHibernate.SQL" additivity="false"> <level value="DEBUG" /> <appender-ref ref="DebugSQL" /> </logger>

EDIT: I can't seem to format this correctly here. See this link for code example

更多推荐

本文发布于:2023-08-01 20:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1363693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   如何使用   SQL   Studio   NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!