asemin.FileLogger
0.3.0
See the version list below for details.
dotnet add package asemin.FileLogger --version 0.3.0
NuGet\Install-Package asemin.FileLogger -Version 0.3.0
<PackageReference Include="asemin.FileLogger" Version="0.3.0" />
<PackageVersion Include="asemin.FileLogger" Version="0.3.0" />
<PackageReference Include="asemin.FileLogger" />
paket add asemin.FileLogger --version 0.3.0
#r "nuget: asemin.FileLogger, 0.3.0"
#:package asemin.FileLogger@0.3.0
#addin nuget:?package=asemin.FileLogger&version=0.3.0
#tool nuget:?package=asemin.FileLogger&version=0.3.0
FileLogger
Microsoft.Extensions.Logging file logger for .NET / ASP.NET Core / .NET Worker.
Why this one?
It is log file appender friendly. That means it does always write in the same (first) log file and on file roll over it moves the content into a new file.
Getting started
TODO: Add nuget package
Either use application builder
using asemin.FileLogger;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddFile();
or use default builder
TODO: Add default builder extension method
Tip: If you do not add any configuration, a default one will be used:
- Log file:
/logs/<appname>.app.log
andappname
is theIHostEnvironment.ApplicationName
- max file size: 10 MiB
- max files: 10
Configuration
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"File": {
"Files": {
"default": {
"File": "logs/logs.log",
"MaxSize": 104857600,
"MaxFiles": 100
},
"other": {
"File": "%ProgramData%/My app/otherLogFile.log",
"MaxSize": 10485760,
"MaxFiles": 10
}
}
}
}
}
In Logging.File.Files
you can add as many files loggers as you want. The names (default
, other
) are only used
by .NET configuration. So you can make proper overrides with debug or production settings.
Property | Default | Description |
---|---|---|
File |
logs/logs.log |
Name of the log file. Supports relative paths, absolut paths and environment parameters expansion (e.g. %appdata% ). |
MaxSize |
10485760 (10 MiB) |
Max size of log file in bytes. If file exceeds this size a roll over will happen. |
MaxFiles |
10 |
Max number of log files. Older files get deleted first. |
C# code
builder.Logging.AddFile(x =>
{
x.Files = new Dictionary<string, LoggerConfig>
{
{
"default",
new LoggerConfig
{
File = @"C:\temp\my app\logs\logs.log",
MaxSize = 100 * 1024 * 1024,
MaxFiles = 25
}
}
};
});
F# code
builder.Logging.AddFile(fun config ->
config.Files <-
dict[("default", LoggerConfig(
File = "mylog.log",
MaxSize = 10 * 1024 * 1024,
MaxFiles = 17))])
TODOs
- add automatic build pipeline
- add nuget package
- add Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder extension method
- try out in serious applications
- add support for different filters for each log file
- Test with Linux
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net6.0
- FSharp.Core (>= 8.0.101)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.