Logging recommendations in nservicebus hosts

All of our handlers have a try catch around the code within the handler and upon an unhandled exception happening simply logs the exception to our log file.

We were wondering if:

  1. Does nservicebus already do the unhandled exception logging for us with its built in logging meaning this is not necessary to do throughout every handler?
  2. Is there an easy way to extend nservicebus to automatically do the above for us so we don’t have to add a try catch + logging + re throwing to all our handlers?
  3. Are there any recommendations on how to perform logging of unhandled exceptions in nservicebus?

Hi

I will respond to you with a set of links, hoping that they will answer your questions (I believe they do ;)). If not feel free to ask further questions:

How error handling work in NServiceBus:
https://docs.particular.net/nservicebus/recoverability/configure-error-handling

Overall when an expcetion is thrown it is used to indicate that the message have failed and should be retried. That exception is logged in NServiceBus Logs.

As you mention host: I will also send a link to critical errors section that cause host to be stoped:
https://docs.particular.net/nservicebus/hosting/critical-errors

Please have a look at the above and let me know if it answers your questions
Michal

Hey,

I was really hoping for answers to the above points ( 1 through 3 )

1, 2 & 3:

Unhandled exceptions happening within handlers/sagas will be logged but if you have any logic that does not run in the context of message processing you will need to do your own logging.

Just try out our recovery sample so you can see for yourself: https://docs.particular.net/samples/errorhandling/

Awesome thanks. So it looks like the exception message is only logged and not the stack trace etc? I was hoping that would not be the case. All-in-All i think i just need to implement a pipeline behavior to catch exceptions and log them how i want.

No, the whole exception is passed to the logger so that includes stacktrace info but it depends on the logger configuration how the exception is logged so with or without a stacktrace.