问题
I'm currently using NHibernate 3.1 in a ASP.Net application and got it working pretty well (with Fluent). I managed to make it log all generated SQL queries to my output tab while debugging by using the following snippet in Application_Start:
private static DebugTextWriter _writer;
protected virtual void Application_Start(object sender, EventArgs e)
{
_writer = new DebugTextWriter();
Console.SetOut(_writer);
}
I recently upgraded NHibernate from 2.1 to 3.1 and now my update and delete statements are no longer being output to the to log...
Do you guys have any idea why?
Thanks
回答1:
I finally found what was causing this behavior. It turns out that the adonet.batch_size entry in the hibernate.cfg.xml file is causing the problem. After removing this property element, the update and delete statements were finally output as expected.
Thanks for your answers and comments.
回答2:
In order to log using log4net, you don't need to define show_sql, you just need to configure the loggers named NHibernate and NHibernate.SQL. Make sure you don't restrict the levels - could it be that you're only logging from level INFO and above, and the messages you're missing are at level DEBUG?
Here is a short tutorial: http://nhforge.org/wikis/howtonh/configure-log4net-for-use-with-nhibernate.aspx
来源:https://stackoverflow.com/questions/5716669/cant-get-nhibernate-3-1-to-log-sql-update-or-delete-statements