Skip to content

Commit

Permalink
Add a few more details about the perspective of the consumer (#40031)
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Mar 15, 2024
1 parent f16ccec commit 9cfe99e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/core/extensions/logging-library-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Logging guidance for .NET library authors
author: IEvangelist
description: Learn how to expose logging as a library author in .NET. Follow the guidance to ensure your library is correctly exposed to consumers.
ms.author: dapine
ms.date: 10/11/2023
ms.date: 03/15/2024
---

# Logging guidance for .NET library authors
Expand Down Expand Up @@ -81,8 +81,11 @@ A common mistake is to use [string interpolation](../../csharp/tutorials/string-

## Use no-op logging defaults

Libraries can default to _null logging_ if no `ILoggerFactory` is provided. The use of _null logging_ differs from defining types as nullable (`ILoggerFactory?`), as the types are non-null. These convenience-based types don't log anything and are essentially no-ops. Consider using any of the available abstraction types where applicable:
There may be times, when consuming a library that exposes logging APIs that expect either an `ILogger` or `ILoggerFactory`, that you don't want to provide a logger. In these cases, the [Microsoft.Extensions.Logging.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Abstractions) NuGet package provides no-op logging defaults.

Library consumers can default to _null logging_ if no `ILoggerFactory` is provided. The use of _null logging_ differs from defining types as nullable (`ILoggerFactory?`), as the types are non-null. These convenience-based types don't log anything and are essentially no-ops. Consider using any of the available abstraction types where applicable:

- <xref:Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance?displayProperty=nameWithType>
- <xref:Microsoft.Extensions.Logging.Abstractions.NullLogger%601?displayProperty=nameWithType>
- <xref:Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory.Instance?displayProperty=nameWithType>
- <xref:Microsoft.Extensions.Logging.Abstractions.NullLoggerProvider.Instance?displayProperty=nameWithType>

0 comments on commit 9cfe99e

Please sign in to comment.