I am using MassTransit 3.5.7. I add the correlation ids before starting the bus:
MessageCorrelation.UseCorrelationId<ICustomerRegistered>(x => x.CustomerGuid);
MessageCorrelation.UseCorrelationId<ICustomerUpdated>(x => x.Customer.Guid);
MessageCorrelation.UseCorrelationId<IOrderPaid>(x => x.OrderGuid);
MessageCorrelation.UseCorrelationId<IOrderPaymentAuthorized>(x => x.OrderGuid);
MessageCorrelation.UseCorrelationId<IOrderPlaced>(x => x.Order.OrderGuid);
MessageCorrelation.UseCorrelationId<IOrderRefunded>(x => x.OrderGuid);
I use Serliog 2.5.0 for logging:
Bus.Factory.CreateUsingAzureServiceBus(serviceBus =>
{
serviceBus.UseSerilog();
...
}
I can see that the CorrelationId is added to the message headers, but it's not added as a custom property to the logs.
What do I need to do in order to log the CorrelationId for all logged messages?
UPDATE:
I implemented a Serilog enricher and a MassTransit custom middleware like here, but the correlation id is only logged in the received (consumed) messages. It is not logged when publishing a message. Does anyone know how can I log the correlation id when publishing a message?