MintPlayer.AspNetCore.LoggerProviders 11.0.1-rc.0

This is a prerelease version of MintPlayer.AspNetCore.LoggerProviders.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MintPlayer.AspNetCore.LoggerProviders --version 11.0.1-rc.0
                    
NuGet\Install-Package MintPlayer.AspNetCore.LoggerProviders -Version 11.0.1-rc.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MintPlayer.AspNetCore.LoggerProviders" Version="11.0.1-rc.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MintPlayer.AspNetCore.LoggerProviders" Version="11.0.1-rc.0" />
                    
Directory.Packages.props
<PackageReference Include="MintPlayer.AspNetCore.LoggerProviders" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MintPlayer.AspNetCore.LoggerProviders --version 11.0.1-rc.0
                    
#r "nuget: MintPlayer.AspNetCore.LoggerProviders, 11.0.1-rc.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MintPlayer.AspNetCore.LoggerProviders@11.0.1-rc.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MintPlayer.AspNetCore.LoggerProviders&version=11.0.1-rc.0&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MintPlayer.AspNetCore.LoggerProviders&version=11.0.1-rc.0&prerelease
                    
Install as a Cake Tool

MintPlayer.AspNetCore.LoggerProviders

A Microsoft.Extensions.Logging provider that writes structured entries — timestamp, level, category, event id, scopes, message and exception — to a file.

Installation

dotnet add package MintPlayer.AspNetCore.LoggerProviders

Quick start

var builder = WebApplication.CreateBuilder(args);

builder.Logging.AddFileProvider(options =>
{
    // Required. Resolve it against a root you control — see "The filename" below.
    options.FileName = Path.Combine(builder.Environment.ContentRootPath, "Log.txt");
});

There is also a parameterless AddFileProvider() for hosts that configure the options elsewhere (services.Configure<FileLoggerOptions>(…), or binding a configuration section).

Calling AddFileProvider() twice is harmless: the provider is registered at most once, so no entry is ever written twice.

Options

Option Default Meaning
FileName (none — required) Path of the log file. Only .txt and .log are accepted, compared case-insensitively.
MinimumLevel LogLevel.Trace Lowest level this provider writes, independently of any ILoggingBuilder filter. LogLevel.None disables the provider.
IncludeScopes true Whether active BeginScope state is written as part of each entry.

Bound from configuration by property name, e.g.

{ "FileLogger": { "FileName": "Log.txt", "MinimumLevel": "Information", "IncludeScopes": true } }
builder.Services.AddOptions<FileLoggerOptions>().Bind(builder.Configuration.GetSection("FileLogger"));
builder.Logging.AddFileProvider();

The entry format

One header line per entry, followed by the exception's own lines if there is one, followed by a blank line (the blank line is what delimits a multi-line entry):

<timestamp> [<Level>] <Category>[<EventId>[:<EventName>]] [=> <scope>]* <message>
<exception.ToString()>
<blank>

For example:

2026-08-27T09:15:42.1234567Z [Error] MintPlayer.Sample.Worker[4711:JobFailed] => RequestId:abc request failed
System.InvalidOperationException: the real cause
   at MintPlayer.Sample.Worker.Run()

  • timestamp — UTC, round-trip ("O") format, invariant culture. It comes from the TimeProvider registered in the container, or the system clock when there is none, so a test can pin it.
  • level — the LogLevel name: Trace, Debug, Information, Warning, Error, Critical.
  • category — omitted when empty.
  • event id — omitted when the id is 0 and unnamed; written as [42] or [42:TheName].
  • scopes — outermost first, each prefixed with =>; omitted when IncludeScopes is off.
  • exception — exception.ToString(), so type, message, stack trace and inner exceptions are all kept. The framework's default message formatter ignores the exception argument, so a logger that writes only the formatted message loses the one thing a log file exists for.

Every field is formatted with the invariant culture, so a file reads identically whatever the host's culture and time zone.

The filename

FileName has no default. An unconfigured provider throws (an OptionsValidationException, when logging is first resolved) instead of quietly writing a relative Log.txt into whatever Directory.GetCurrentDirectory() happens to be — which under IIS or a Windows Service is neither the content root nor necessarily writable. Point it at a root you control: ContentRootPath, a configured log directory, or an absolute path.

A relative path is accepted if you ask for one explicitly, and is resolved to an absolute path once, when the provider is created; the log file therefore never moves if the process later changes its working directory. The directory must exist — the provider does not create it.

Everything about the filename (presence, extension, resolution) is validated once, at that point, rather than on every write.

Concurrency and disposal

Writes are serialised on a lock shared by every logger targeting the same resolved path, and each entry is a single open, append, close with FileShare.ReadWrite. So:

  • concurrent loggers cannot lose an entry to a sharing violation;
  • readers are never locked out — File.ReadAllText, an editor or tail can read the file while the application is running;
  • nothing is buffered, so an entry is on disk before Log returns, and disposing the provider owes no flush.

A foreign process that holds the file with a share mode excluding writers still wins; the resulting IOException surfaces to the caller rather than being swallowed.

Scopes

The provider implements ISupportExternalScope, so it writes the logger factory's shared scope stack: a scope opened anywhere is recorded on every entry made inside it, whatever the category. BeginScope never returns null (with IncludeScopes = false it returns an inert scope).

Registering your own provider

builder.Logging.TryAddProvider(serviceProvider => new MyLoggerProvider(...));

Registers the provider type at most once. Deduplicating matters here: a logger provider registered twice makes the factory write every entry twice, and registering twice is easy — a library's own AddX() and the app's explicit call cannot see each other.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

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
11.0.1 103 11/12/2026
11.0.1-rc.1 70 10/24/2026
11.0.1-rc.0 94 9/17/2026
11.0.0 151 8/27/2026
10.1.0 88 11/12/2026
10.0.1 174 1/19/2026
10.0.0 336 11/13/2025
10.0.0-rc.1 186 10/2/2025
9.0.0 203 11/13/2024
8.0.1 267 1/28/2024
8.0.0 200 1/28/2024