CodeFoxtrot.FileLogger 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeFoxtrot.FileLogger --version 1.0.0                
NuGet\Install-Package CodeFoxtrot.FileLogger -Version 1.0.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="CodeFoxtrot.FileLogger" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeFoxtrot.FileLogger --version 1.0.0                
#r "nuget: CodeFoxtrot.FileLogger, 1.0.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.
// Install CodeFoxtrot.FileLogger as a Cake Addin
#addin nuget:?package=CodeFoxtrot.FileLogger&version=1.0.0

// Install CodeFoxtrot.FileLogger as a Cake Tool
#tool nuget:?package=CodeFoxtrot.FileLogger&version=1.0.0                

FileLogger - Simple is Good

  • Simple implementation supporting asynchronous Console and File logging.
  • Rolling logs with configurable maximum size, maximum count and append of existing log.
  • Configurable minimum log level.
  • Indent multiline messages for easier reading and analysis.
  • Configurable color scheme for Console log messages, for easier reading.

Console colors

Configuration

Example appsettings.json configuration:

{
  "Logging": {
    "LogLevel": {
    "Default": "Debug",
    "System": "Information",
    "Microsoft": "Error"
    },
    "FileLogger": {
      "LogName": "FileLoggerDemo",
      "LogFolder": "",
      "LogMaxBytes": 52428800,
      "LogMaxCount": 10,
      "LogMinLevel": "Trace",
      "IndentMultilineMessages": true,
      "ConsoleLogging": true,
      "EnableConsoleColors": true,
      "LogLevelColors": {
        "Trace": "Cyan",
        "Debug": "Blue",
        "Information": "Green",
        "Warning": "Yellow",
        "Error": "Red",
        "Critical": "Magenta",
        "None": "White"
      }
    }
  }
}

Example IHostBuilder implementation:

logging.AddFileLogger(configure =>
  {
    configure.LogName = "FileLoggerDemo";
    configure.LogFolder = $@"{Environment.CurrentDirectory}\log";
    configure.LogMaxBytes = 50 * 1048576;
    configure.LogMaxCount = 10;
    configure.LogMinLevel = LogLevel.Trace;
    configure.IndentMultilineMessages = true;
    configure.ConsoleLogging = true;
    configure.EnableConsoleColors = true;
    configure.LogLevelColors = new Dictionary<LogLevel, ConsoleColor>()
    {
      [LogLevel.Trace] = ConsoleColor.Cyan,
      [LogLevel.Debug] = ConsoleColor.Blue,
      [LogLevel.Information] = ConsoleColor.Green,
      [LogLevel.Warning] = ConsoleColor.Yellow,
      [LogLevel.Error] = ConsoleColor.Red,
      [LogLevel.Critical] = ConsoleColor.DarkRed,
      [LogLevel.None] = ConsoleColor.White
    };
  });

Indentation

IndentMultilineMessages=true

2022-04-04--18.10.20|INFO|FileLoggerDemo.App|{
                                               "Date": "4/4/2022",
                                               "Location": "Center Moriches",
                                               "TemperatureCelsius": 20,
                                               "Summary": "Nice"
                                             }

IndentMultilineMessages=false

2022-04-04--18.11.19|INFO|FileLoggerDemo.App|{
  "Date": "4/4/2022",
  "Location": "Center Moriches",
  "TemperatureCelsius": 20,
  "Summary": "Nice"
}

Roadmap

  • Support for Daily, Weekly or Monthly rolling log, up to 1GB maximum single log file.

Reference

https://docs.microsoft.com/en-us/dotnet/core/extensions/custom-logging-provider

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CodeFoxtrot.FileLogger:

Package Downloads
CodeFoxtrot.WindowsHelpers

Useful set of helper methods for C# in the Microsoft Windows environment.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 70 11/18/2024
1.0.8 255 12/1/2023
1.0.7 210 4/23/2023
1.0.6 300 12/24/2022
1.0.5 450 7/8/2022
1.0.2 461 4/10/2022
1.0.0 424 4/5/2022