Skip to content

Instantly share code, notes, and snippets.

@ramonsmits
Created July 11, 2017 13:17
Show Gist options
  • Select an option

  • Save ramonsmits/2291cb57acb4659d4efcb693e79048fc to your computer and use it in GitHub Desktop.

Select an option

Save ramonsmits/2291cb57acb4659d4efcb693e79048fc to your computer and use it in GitHub Desktop.
Log the message ID's from the messages that have been dispatched to the transport
using System;
using System.Threading.Tasks;
using NServiceBus.Logging;
using NServiceBus.Pipeline;
/// <code>
/// endpointConfiguration.Pipeline.Register(behavior: new LogDispatchedMessageIdBehavior(), description: LogDispatchedMessageIdBehavior.Description);
/// </code>
class LogDispatchedMessageIdBehavior : Behavior<IBatchDispatchContext>
{
public const string Description = "Log the message ID of the message that has been dispatched.";
static readonly ILog Log = LogManager.GetLogger(nameof(LogDispatchedMessageIdBehavior));
public override Task Invoke(IBatchDispatchContext context, Func<Task> next)
{
var messageIds = string.Join(", ", context.Operations.Select(x => x.Message.MessageId));
Log.InfoFormat("Dispatching messages {0}", messageIds);
return next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment