How to show Log4Net info in NUnit (from NHibernate)
OK, simple little problem. You are trying to figure out a problem with an NHibernate mapping file, you know that NHibernate uses Log4Net to log all sorts of interesting info, but you aren’t seeing it when you run your NUnit tests.
1. Add an app.config to your test project (if there isn’t one there already) and add this code:
This configures Log4Net to log almost everything to the console window…which NUnit keeps track of.
2. In your test class, add the following line:
OK, so now anything that is logged with Log4net will show up in NUnit.
3. Double check your NHibernate settings (mine are in the file hibernate.cfg.xml). Make sure show_sql is true
Regardless of the log4net status with NUnit, this will display the SQL query being executed by NHibernate in NUnit.
Now a word of warning, if you are having trouble with NHibernate, and you use this to get the log info out of it. To turn off NHibernate logging, but leave logging on for everything else, add this to the app.config (around line 19 of my app.config text from above):