-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: SQL Logging
PostPosted: Tue Oct 25, 2005 10:28 am 
Beginner
Beginner

Joined: Mon Oct 03, 2005 4:59 am
Posts: 26
Location: Cambridge, UK
I'm using NHibernate in an ASP.NET application for a client who wants all SQL statements made against the database to be logged to a file. I'm having some trouble getting NHibernate to do this in a useful way.

setting show_sql=true in the .config file doesn't help much, since a) that is hardcoded to stdout, which is not suitable for asp.net, and b) it doesn't log the parameter values for parametrized queries. "UPDATE myTable SET value = @p0 WHERE ID = @p1" isn't very valuable.

Using log4net with <priority value="DEBUG"> gives nice output, but makes log files that are too large for production use. Using <priority value="INFO"> makes managable file sizes, but
doesn't record parameter values, and, surprisingly, logs SELECT statements but not DELETE or UPDATEs.

What I want is, for every SQL statement executed, output something like this, (cut'n'pasted from log file with <priority value="DEBUG">, and trimmed some), but without the vast quantities of other output:
Code:
2005-10-25 15:08:21,421 [872] DEBUG NHibernate.Type.BooleanType [(null)] <(null)> - binding 'False' to parameter: 0
2005-10-25 15:08:21,421 [872] DEBUG NHibernate.Type.Int32Type [(null)] <(null)> - binding '1' to parameter: 1
...
2005-10-25 15:08:21,421 [872] DEBUG NHibernate.Type.Int32Type [(null)] <(null)> - binding '9' to parameter: 10
2005-10-25 15:08:21,421 [872] DEBUG NHibernate.SQL [(null)] <(null)> - UPDATE tblLinePositionTasks SET sat = @p0, TaskTypeID = @p1, thu = @p2, tue = @p3, GradeID = @p4, wed = @p5, mon = @p6, sun = @p7, PositionID = @p8, fri = @p9 WHERE ID = @p10


Is there any way to configure this, or would I have to mess with NHibernate's code?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 6:01 pm 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
Why don't you just use profiler to log all the statements?


Top
 Profile  
 
 Post subject: SQL Logging
PostPosted: Wed Oct 26, 2005 7:16 am 
Just add a new logger to your config file:

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


This one will only log SQL statements.


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.