Skip to main content

Library for using scopes with Microsoft.Extensions.Logging.

Total Downloads
29.7K
29,677
Published
Aug 24, 2025
1y ago

Get Started

dotnet add package Nito.Logging --version 2.0.2
ProductVersions
.NET
net6.0net8.0
.NET Standard
netstandard2.0
Other
.NETFramework4.6.2

README

Logo

Nito.Logging Build status codecov NuGet version API docs

A library for using scopes with Microsoft.Extensions.Logging.

What It Does

This library has two parts:

  1. DataScopes provides the BeginDataScope extension methods for ILogger, which allow you to attach name/value pairs of metadata onto your log messages.
  2. 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

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.