I have following situation: My application which uses NServiceBus has to work with remote MSSQL Server which often not available, so application fails after some time. Is there a way to intercept that event using NServiceBus and send email (or perform any other action) before application closes?
NServiceBus has some options, but also some caveats
I am assuming you're not using the remote SQL Server as a transport, because that would make things even more difficult.
Messages get retried when something fails. NServiceBus is unaware of the severity of the error, etc. but you can work with the immediate, delayed and failed notifications. Documentation can be found here.
You can also use heartbeats to see if an NServiceBus endpoint is still alive, or write custom checks. More info here: