Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Modernization
Samples

NServiceBus.Extensions.Logging Upgrade Version 3 to 4

NServiceBus 10.2 introduces built-in support for Microsoft.Extensions.Logging when hosting endpoints via IServiceCollection.AddNServiceBusEndpoint. This makes the NServiceBus.Extensions.Logging package unnecessary. The recommended path is to migrate to the .NET Generic Host with AddNServiceBusEndpoint and remove the bridge package.

ExtensionsLoggerFactory is deprecated

The ExtensionsLoggerFactory class has been deprecated. When hosting with the .NET Generic Host using AddNServiceBusEndpoint, NServiceBus automatically uses the host's configured Microsoft.Extensions.Logging infrastructure. Remove any call to LogManager.UseFactory(new ExtensionsLoggerFactory(...)), then remove the NServiceBus.Extensions.Logging package reference.

Recommended: Use the Generic Host

When using AddNServiceBusEndpoint, no code changes are required beyond removing the obsolete configuration:

Replace:

var builder = Host.CreateApplicationBuilder();

var loggerFactory = LoggerFactory.Create(logging =>
{
    logging.AddNLog();
});

LogManager.UseFactory(new ExtensionsLoggerFactory(loggerFactory));

builder.Services.AddNServiceBusEndpoint(endpointConfiguration);

with:

var builder = Host.CreateApplicationBuilder();

builder.Logging.AddNLog();

builder.Services.AddNServiceBusEndpoint(endpointConfiguration);

For more information about hosting with AddNServiceBusEndpoint, see Hosting with Microsoft.Extensions.Hosting.

Self-hosted endpoints

For endpoints that are not yet using the .NET Generic Host and still call Endpoint.Start, logging providers can be registered on the endpoint's service collection via RegisterComponents as a temporary bridge:

var endpointConfiguration = new EndpointConfiguration("MyEndpoint");

endpointConfiguration.RegisterComponents(services =>
{
    services.AddLogging(logging => logging.AddNLog());
});

var endpointInstance = await Endpoint.Start(endpointConfiguration);

Remove the package

After removing any use of ExtensionsLoggerFactory, remove the NServiceBus.Extensions.Logging package reference from the project. The built-in Microsoft.Extensions.Logging integration is provided by the core NServiceBus package starting with version 10.2.