views:

96

answers:

1

Hi,

I have a .net service that processes messages. For any failures, i use log4net and write to a file. I added an SMTP appender for this. The issue is that I only want to send one email when something goes wrong. The MaxRetries in my app.config is set to 5 and this is correct, 5 errors are logged in the log4net file but 5 emails are also sent.

Is there some way I can get a handle on the max retries and fire my email when that is reached?

Thanks for your help.

+2  A: 

Add a regular nservicebus endpoint that reads from the error queue. Add a handler for IMessage and within that handler add a call to smtpclient.send.

I have a post that tries to explain error handling for message based systems that might be of interest: http://andreasohlund.blogspot.com/2010/03/errorhandling-in-message-oriented-world.html

Hoep this helps!

Andreas
Hi, thanks for the reply. I already use smtpclient send however, the issue is that 5 emails are sent if the max retries is set to 5. I want to send only one email regardless of how many retries are carried out.
Gilbert
That's why you should monitor the error queue and only send the emails when messages are put there. Messages will be put in the error queue after all configured retries has been performed. Does that make sense?
Andreas
Ah, the penny drops. Thanks for that, i'll have a look.Cheers.
Gilbert