Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Error notifications

Component: NServiceBus
NuGet Package: NServiceBus (9.1)

Error notifications are available for several events:

The following example shows how to be notified every time a message is handled by recoverability. While this code writes to the console any other action could be taken, for example sending an email or writing to a monitoring system.

var recoverability = endpointConfiguration.Recoverability();

recoverability.Immediate(settings => settings.OnMessageBeingRetried((retry, ct) =>
{
    log.Info($"Message {retry.MessageId} will be retried immediately.");
    return Task.CompletedTask;
}));

recoverability.Delayed(settings => settings.OnMessageBeingRetried((retry, ct) =>
{
    log.Info($@"Message {retry.MessageId} will be retried after a delay.");
    return Task.CompletedTask;
}));

recoverability.Failed(settings => settings.OnMessageSentToErrorQueue((failed, ct) =>
{
    log.Fatal($@"Message {failed.MessageId} will be sent to the error queue.");
    return Task.CompletedTask;
}));

Message Body

Since the message could have failed due to a deserialization exception, it is not possible for the API to provide the instance of the message. For the same reason is it recommended that consumers of this API do not attempt to deserialize the message instance. If the message contents are required for debugging purposes, convert the message body to a string using the .NET Encoding APIs.

Samples