liveBook · Manning

Rolling file provider

As explained in ASP.NET Core in Action, 3e

A rolling file provider is a logging provider that writes messages to files and starts a new file according to a rolling policy such as a daily interval.

A rolling file provider writes application log messages to files and starts a new file according to a rolling policy, such as once per day. section 26.3

Add a provider to an ASP.NET Core application in three steps:

  • Install the NetEscapades.Extensions.Logging.RollingFile NuGet package with Visual Studio or the .NET CLI. section 26.3
  • Call AddFile() on WebApplicationBuilder.Logging. section 26.3
  • Run the application and generate logs; each ILogger message is sent to every configured provider. section 26.3
Listing 26.5 Adding a third-party logging provider to WebApplicationBuilder
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);   #1
builder.Logging.AddFile();                                            #2
 
WebApplication app = builder.Build();
 
app.MapGet("/", () => "Hello world!");
 
app.Run();
#1 The WebApplicationBuilder configures the console and debug providers as normal.
#2 Adds the new file logging provider to the logger factory

A minimal application adds the rolling file provider while retaining the console and debug providers configured by WebApplicationBuilder. section 26.3

Keep console and file logging together

When an application logs a message, the console can display it during local development while the rolling file provider persists it for later inspection. section 26.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Covers package installation and AddFile registration, but stops short of detailed rolling-policy customization.
Examples
Uses a minimal WebApplicationBuilder application and simultaneous console, debug, and rolling-file outputs.
What you can do after
Configure an ASP.NET Core application to write logs to a new file each day.
How it connects
Connects logging providers with ILogger, WebApplicationBuilder, and Serilog file providers.

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.