Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 2.69 KB

extensions-logging.md

File metadata and controls

51 lines (36 loc) · 2.69 KB
title summary reviewed component related
NServiceBus.Extensions.Logging
Logging with Microsoft.Extensions.Logging
2025-03-21
Extensions.Logging
samples/logging/extensions-logging

Note

It is recommended to directly use the Microsoft.Extensions.Logging 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.Extensions.Logging 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.

Note

This package should only be used when configuring logging in a self-host model. If hosting with the .NET Generic Host use NServiceBus.Extensions.Hosting package instead.

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<TCategoryName>. Usage of ILogger<TCategoryName> 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:

snippet: ExtensionsLogging