Search code examples
nservicebus

Nsb: Custom behavior after every handler


We want to log every occurrence of a handler running to completion and we're wondering what's the cleanest way to do it.

More specifically, when a Handler completes, we want to write some basic information like the type of the message that was processed etc, to a Db.

One way to do it is by creating and sending a new message (publishing an event) at the end of each handler.

But we're wondering if there is another way to do this without "polluting" the message handlers with those extra line of code :) For example, if after a Handler runs to completion, another method defined elsewhere would pick up execution and handle the logic of writing to the database.

Hope I made myself clear enough. Thanks


Solution

  • You could use the auditing pipeline and forward the audit messages to your audit queue and handle a copy of all messages there...

    Here is some more info: https://docs.particular.net/nservicebus/operations/auditing?version=core_7.2

    Does that make sense?