It is recommended to directly use the Microsoft. package to log entries as it also supports semantic logging. Please see Logging in .NET Core and ASP.NET Core for further details.
The
NServiceBus.package'sExtensions. Logging ExtensionsLoggerFactoryis deprecated starting with NServiceBus 10.2.0. When hosting with the .NET Generic Host usingAddNServiceBusEndpoint, NServiceBus natively usesMicrosoft.and the bridge package is no longer required. See the upgrade guide for migration details.Extensions. Logging
The NServiceBus. package provides support for writing NServiceBus log entries via the Microsoft.Extensions.Logging abstractions. With this common logging abstraction, it is possible to log to different logging providers. Some third-party frameworks can perform semantic logging, also known as structured logging.
Compatibility
Microsoft.Extensions.Logging can be used to replace the following providers:
- Common.Logging (Only if the configured provider in Common.Logging is supported by Microsoft.Extensions.Logging)
- Log4net
- NLog
Supported providers
NServiceBus supports the following logging frameworks via Microsoft.Extensions.Logging:
- elmah.io
- Gelf
- JSNLog
- KissLog.net
- Log4Net
- Loggr
- NLog
- Sentry
- Serilog
- Stackdriver
For an up-to-date list, see the Microsoft.Extensions.Logging fundamentals documentation, specifically the built-in and third-party providers sections.
Support for ILogger
Microsoft.Extensions.Logging abstractions provide a generic interface that allows a dependency injection-friendly way to use loggers. NServiceBus.Extensions.Logging does not register any resolver for type ILogger. Usage of ILogger requires the use an external dependency injection container like NServiceBus.Extensions.DependencyInjection that contains registrations for the Microsoft.Extensions.Logging abstractions.
Usage
Configure NServiceBus to use Microsoft.Extensions.Logging:
NServiceBus.Logging.LogManager.UseFactory(new ExtensionsLoggerFactory(extensionsLoggingFactory));