tags:

views:

330

answers:

2

Let's say if I encounter an error in NHibernate db update, and when such an exception is thrown, I want to log it in the log table in the db, via NHibernate again.

Now, since I can't reuse NHibernate session after an exception thrown, I will get an error when I log into the log table. How to best handle this situation?

+3  A: 

Open a new session.

Or use a logging framework like log4net with ADO.NET appender and do it completely separately out of NHibernate environment.

Rashack
+2  A: 

IMO logging should be a cross cutting concern of your application. You should not try to reuse the same session in order to log errors. NHibernate already uses log4net. All you need is to configure an appender that will write logs to the SQL database.

Darin Dimitrov