NServiceBus 10.2 introduces built-in support for Microsoft.Extensions.Logging when hosting endpoints via IServiceCollection.. This makes the NServiceBus. package unnecessary. The recommended path is to migrate to the .NET Generic Host with AddNServiceBusEndpoint and remove the bridge package.
NServiceBus version 10.2 or later is required.
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. infrastructure. Remove any call to LogManager., then remove the NServiceBus. 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., 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);
Endpoint. and RegisterComponents are also deprecated in NServiceBus 10.2. Transition to the Generic Host with AddNServiceBusEndpoint as soon as possible.
Remove the package
After removing any use of ExtensionsLoggerFactory, remove the NServiceBus. package reference from the project. The built-in Microsoft. integration is provided by the core NServiceBus package starting with version 10.2.