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
