简体   繁体   中英

Can NServiceBus's use of NHibernate be exposed in logging with Log4Net?

I'd like to be able to expose the usage of NHibernate by NServiceBus through logging. In paricular, I'd like to see when transactions are committed or rolled back.

We're currently investigating an issue with one of our Sagas where it appears the roll back process is failing due to DB locking. We'd like to confirm if and when it's attempting to roll back or commit, and whether this is successful.

We are currently using Log4Net to log the activity of NServiceBus and NHibernate, independently, but do not receive logging information regarding Saga transactions - committing/rolling back.

Many thanks in advance.

If you are already using Log4Net to log NHibernate activity, you should be able to already see any transaction-based NHibernate logging information unless your configuration is setup to filter out certain NHibernate classes from logging.

Take a look at the following article on configuring Log4Net to log NHibernate logging messages. Once you've got that done, you should be able to see all logging data.

Configure Log4Net for use with NHibernate

You could also explicitly setup a Log4Net logger to capture the transaction logging message by adding this node in your Log4Net configuration:

<logger name="NHibernate.Transaction.AdoTransaction">
  <level value="DEBUG" />
</logger>

If that doesn't work, you can dig a little deeper. Here's some stuff to consider to get you started:

Let me preface by stating that I've never used Sagas with NServiceBus but doing a little research, here's what I can conclude.

NServiceBus internally creates its own NHibernate configuration to handle persisting Sagas. The configuration of that NHibernate configuration instance is done in a .config file. Take a look under the Sagas heading on the following page to get a look at what the configuration looks like:

http://docs.particular.net/nservicebus/nhibernate/

Taking a look at that, you should be able to add any new keys that may get you what you need.

You could potentially add an Interceptor or Event Listener to the configuration which is basically a class that will be called when certain actions are about to be performed by NHibernate such as saving/updating/transactions/etc. You can Google around for NHibernate Interceptors and/or Event Listeners if need be to get the whole scoop on what they do and how to use them or visit the NHibernate documentation here: http://nhibernate.info/doc/nh/en/index.html#objectstate-events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM