Last active
November 20, 2025 12:54
-
-
Save ramonsmits/cc3a8b91e1d496a10e512cdb048d6c2b to your computer and use it in GitHub Desktop.
NServiceBus behavior that logs incoming message details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Register as: | |
| // | |
| // endpointConfiguration.Pipeline.Register(new LogIncomingMessageDetails(), nameof(LogIncomingMessageDetails)); | |
| // | |
| sealed class LogIncomingMessageDetails : Behavior<IIncomingPhysicalMessageContext> | |
| { | |
| static readonly ILog logger = LogManager.GetLogger<LogIncomingMessageDetails>(); | |
| public override async Task Invoke(IIncomingPhysicalMessageContext context, Func<Task> next) | |
| { | |
| var nativeId = context.Message.NativeMessageId; | |
| var id = context.MessageId; | |
| var enclosedMessageTypes = context.MessageHeaders[Headers.EnclosedMessageTypes]; | |
| try | |
| { | |
| logger.DebugFormat("Processing {0}, {1}, {2}", nativeId, id, enclosedMessageTypes); | |
| await next(); | |
| logger.DebugFormat("Completed {0}, {1}, {2}", nativeId, id, enclosedMessageTypes); | |
| } | |
| catch | |
| { | |
| logger.ErrorFormat("Failed {0}, {1}, {2}", nativeId, id, enclosedMessageTypes); | |
| throw; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment