We’ve just released NServiceBus.Extensions.Logging 1.0.0.
What’s New
The NServiceBus.Extensions.Logging package allows your NServiceBus endpoints to be configured with any third-party logging framework implementing the Microsoft.Extensions.Logging abstraction.
This package removes the need to use NServiceBus specific logging providers if these logging frameworks support Microsoft.Extensions.Logging.
The documentation contains an up-to-date list of existing NServiceBus logging providers that are obsolete due to these providers natively supporting Microsoft.Extensions.Logging.
This what I have so far, using the other extensions libraries (hosting and DI):
public class Program
{
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var loggerFactory = new ExtensionsLoggerFactory(host.Services.GetService<ILoggerFactory>());
NServiceBus.Logging.LogManager.UseFactory(loggerFactory);
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseNServiceBus(hostBuilderContext =>
{
var endpointConfiguration = new EndpointConfiguration("WorkerService");
endpointConfiguration.UseTransport<LearningTransport>();
endpointConfiguration.UsePersistence<LearningPersistence>();
// configure endpoint here
return endpointConfiguration;
});
}
I don’t see anything in the console, and it looks like everything is still logged to text. I can’t supply the logger factory inside the endpoint configuration block since I don’t have access to a container or anything.
Is it expected that I must use some 3rd-party logger with this library? And not the default one?
Actually, I’m not even sure how to use this with a 3rd party logger. The NLog example isn’t using DI or hosting. If I need an instance of the logger factory, I can’t get at that until the .NET Core host is built.
Maybe the .NET Core host library should directly support .NET Core logging, like it does DI?