Exit a distributed transaction for one of my Entity Framework ObjectContexts

I am using NServiceBus with distributed transactions. This usually works fantastic. Either my post succeeds or fails. All or nothing.

However, I am also trying to write diagnostic data to my database. This is done for a separate ObjectContext. For this, I would like it to persist in the database regardless of the success or failure of the Distributed Transaction.

Is there a way to bind one (and only one) data context to a database outside of a distributed transaction? (And keep the rest in them?)


source to share

3 answers

Try this to suppress your distributed transaction for auditing:

using (new TransactionScope(TransactionScopeOption.Suppress))
    // Create logging context and audit your data




One option (if 3.0 is used) is to create UoW:


And there it suppresses the transaction and writes the log.



NSB has a built in way of auditing . I would recommend enabling this and working with log / audit on a different endpoint.



All Articles