0

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

  • What you want to do can be achieved using a custom logger that writes to the database. The problem of adding an additional step in the handler / behavior chain is that if your step fails (e.g. fail to write to the database), it will cause the message to retry which might be undesired. – Hadi Eskandari May 01 '19 at 05:50
  • Thanks. Could you point me to what you mean exactly when you say it can be achieved using a custom logger? Ty – Torfi Karl May 02 '19 at 23:06

1 Answers1

1

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?

Sean Farmar
  • 2,254
  • 13
  • 10
  • Yes that makes sense thanks. Is it possible to add a custom Behavior at the end of the mandatory pipeline stage, ie to be run after a Handler completes, but before transitioning to a Audit/Forwarding pipeline stage? – Torfi Karl May 01 '19 at 01:21
  • You can try this... https://docs.particular.net/nservicebus/pipeline/manipulate-with-behaviors? But It's complicated... :-), not sure it's worth the effort... – Sean Farmar May 01 '19 at 15:12