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?