I have just released version 1.0 of the Rolling File Logger Provider as part of Essential Logging on Github, a port of my .NET diagnostics library across to Microsoft.Extensions.Logging.
To use, add the Essential.LoggerProvider.RollingFile package to your project via Nuget:
dotnet add package Essential.LoggerProvider.RollingFile
Then reference the namespace, and add the logger provider during host construction:
using Essential.LoggerProvider;
// ...
.ConfigureLogging((hostContext, loggingBuilder) =>
{
loggingBuilder.AddRollingFile();
})
Example output, using the default format (customisable):
The project also includes a Hello File Logging example, using a worker BackgroundService and high performance logging.
Configuration
The logger uses a custom template for the log file name, allowing it to roll based on the date, and a custom template for the log format.
{
"Logging": {
"RollingFile": {
"FilePathTemplate": "{BaseDirectory}/{ApplicationName}-{DateTime:yyyy-MM-dd}.log",
"IncludeScopes": true,
"IsEnabled": true,
"Template": "{DateTime:u} [{ThreadId}] {LogLevel} {CategoryName} {Id}: {Message}{ScopeList} {Exception}"
}
}
}
The template formatter includes different presentations of log information (log level, short code, event ID, scopes, etc), system information (thread, user, machine name, time, etc), and other values useful for logging (system directories, environment variables, etc).
Future directions
I'll be adding some functionality to integrate with my Syslog.StructuredData project, port more of my diagnostics trace listeners across as logger providers, and introduce some new ones.
Looks good! Maybe it’s my old eyes but the output is too small to make sense of and when enlarged just pixelates. Could you gives us a higher-res image or maybe sut and paste some output into the article? Thank you!