Friday, January 10, 2020

MassTransit 6–Serilog integration

Before MassTransit 6, separate NuGet packages existed that allowed you to integrate the logging framework of your choice with MassTransit. In our case we were using Serilog and a MassTransit.SerilogIntegration NuGet package to bring the 2 together.

In MassTransit 6 the previous abstraction has been removed and is replaced by Microsoft.Extensions.Logging.Abstractions.

To enable integration you need to call

MassTransit.Context.LogContext.ConfigureCurrentLogContext(loggerFactory);

before configuring the bus or directly pass on the ILogger instance

MassTransit.Context.LogContext.ConfigureCurrentLogContext(logger);

Integration with Serilog can now be done through the serilog-extensions-logging NuGet package.

More information here; https://www.nuget.org/packages/MassTransit.SerilogIntegration/