asemin.FileLogger 0.3.0

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="asemin.FileLogger" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="asemin.FileLogger" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="asemin.FileLogger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add asemin.FileLogger --version 0.3.0
                    
#r "nuget: asemin.FileLogger, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package asemin.FileLogger@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=asemin.FileLogger&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=asemin.FileLogger&version=0.3.0
                    
Install as a Cake Tool

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 and appname is the IHostEnvironment.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 120 4/12/2025
1.0.0 278 5/18/2024
0.9.0 160 4/17/2024
0.8.0 177 2/19/2024
0.7.0 156 2/19/2024
0.6.0 151 2/18/2024
0.4.0 142 2/17/2024
0.3.0 144 2/17/2024
0.2.0 142 2/17/2024
0.1.0 137 2/17/2024