Overview
Middleware that writes log files in the W3C standard format.
Enabling
Call UseW3Logging
:
Program.cs
var app = builder.Build();
app.UseW3CLogging();
app.UseRouting();
Configuration
Call AddW3CLogging
:
Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddW3CLogging(logging =>
{
// Log all W3C fields
logging.LoggingFields = W3CLoggingFields.All;
logging.AdditionalRequestHeaders.Add("x-forwarded-for");
logging.AdditionalRequestHeaders.Add("x-client-ssl-protocol");
logging.FileSizeLimit = 5 * 1024 * 1024;
logging.RetainedFileCountLimit = 2;
logging.FileName = "MyLogFile";
logging.LogDirectory = @"C:\logs";
logging.FlushInterval = TimeSpan.FromSeconds(2);
});