Nito.Logging
2.0.2
Prefix Reserved
dotnet add package Nito.Logging --version 2.0.2
NuGet\Install-Package Nito.Logging -Version 2.0.2
<PackageReference Include="Nito.Logging" Version="2.0.2" />
<PackageVersion Include="Nito.Logging" Version="2.0.2" />
<PackageReference Include="Nito.Logging" />
paket add Nito.Logging --version 2.0.2
#r "nuget: Nito.Logging, 2.0.2"
#:package Nito.Logging@2.0.2
#addin nuget:?package=Nito.Logging&version=2.0.2
#tool nuget:?package=Nito.Logging&version=2.0.2
Nito.Logging

A library for using scopes with Microsoft.Extensions.Logging.
What It Does
This library has two parts:
DataScopes
provides theBeginDataScope
extension methods forILogger
, which allow you to attach name/value pairs of metadata onto your log messages.ExceptionLoggingScope
captures logging scopes when an exception is thrown, and applies those logging scopes when the exception is logged. In other words, if you find your exception logs are missing useful information from your logging contexts, install this library and enjoy rich logs again!
Getting Started
First, install the Nito.Logging
package.
To attach data scopes to your logs, call BeginDataScope
on any ILogger
or ILogger<T>
. You can pass an anonymous object, any number of (string, object)
tuples, or a collection of KeyValuePair<string, object>
(such as a Dictionary<string, object>
). See the unit tests for examples.
To preserve logging scopes for exceptions, add a call to AddExceptionLoggingScopes()
in your service registration after all loggers have been configured.
Your service registration will look something like this:
public void ConfigureServices(IServiceCollection services)
{
/* Configure all loggers here */
...
services.AddExceptionLoggingScopes();
...
}
Now all logs of exceptions will include the logging scopes at the point they were thrown!
Alternatives
- Throw context enricher for Serilog - essentially the same as
ExceptionLoggingScope
, but for Serilog only.
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.2
- Nito.Logging.DataScopes (>= 2.0.2)
- Nito.Logging.ExceptionLoggingScope (>= 2.0.2)
-
.NETStandard 2.0
- Nito.Logging.DataScopes (>= 2.0.2)
- Nito.Logging.ExceptionLoggingScope (>= 2.0.2)
-
net6.0
- Nito.Logging.DataScopes (>= 2.0.2)
- Nito.Logging.ExceptionLoggingScope (>= 2.0.2)
-
net8.0
- Nito.Logging.DataScopes (>= 2.0.2)
- Nito.Logging.ExceptionLoggingScope (>= 2.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.0.2 | 0 | 8/24/2025 |
2.0.1 | 17 | 8/16/2025 |
2.0.0 | 3,002 | 10/1/2024 |
1.0.1 | 3,771 | 2/19/2021 |
1.0.0 | 625 | 10/25/2020 |
1.0.0-pre06 | 486 | 10/25/2020 |
1.0.0-pre05 | 418 | 10/24/2020 |
1.0.0-pre04 | 427 | 9/13/2020 |
1.0.0-pre03 | 560 | 9/12/2020 |
1.0.0-pre02 | 434 | 9/12/2020 |