Plinth.Logging.Host 1.8.1

Prefix Reserved
dotnet add package Plinth.Logging.Host --version 1.8.1
                    
NuGet\Install-Package Plinth.Logging.Host -Version 1.8.1
                    
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="Plinth.Logging.Host" Version="1.8.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plinth.Logging.Host" Version="1.8.1" />
                    
Directory.Packages.props
<PackageReference Include="Plinth.Logging.Host" />
                    
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 Plinth.Logging.Host --version 1.8.1
                    
#r "nuget: Plinth.Logging.Host, 1.8.1"
                    
#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 Plinth.Logging.Host@1.8.1
                    
#: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=Plinth.Logging.Host&version=1.8.1
                    
Install as a Cake Addin
#tool nuget:?package=Plinth.Logging.Host&version=1.8.1
                    
Install as a Cake Tool

README

Plinth.Logging.Host

Logging utilities for hosted applications and services

Provides simple logging configuration for console applications, Windows services, and Azure Functions using the Plinth logging ecosystem.

Components

  • StaticLogManagerSetup - Utility for configuring logging in Program.cs
    • Supports Console, Debug, and File logging
    • Supports Azure Functions with single-threaded logging contexts
  • FileLogging - Simple file logging provider with append and rolling file support

👉 For sophisticated logging scenarios, use Plinth.Logging.NLog instead.

Usage

1. Console Logging

Configure logging to the console with sensible defaults:

using Plinth.Logging.Host;

class Program
{
    static void Main(string[] args)
    {
        var log = StaticLogManagerSetup.ConfigureForConsoleLogging();

        log.Info("Application started");
        log.Debug("Debug information");
        log.Warn("Warning message");
        log.Error("Error occurred");
    }
}

With custom formatting:

var log = StaticLogManagerSetup.ConfigureForConsoleLogging(
    minLevel: LogLevel.Debug,
    configAction: c =>
    {
        c.ColorBehavior = LoggerColorBehavior.Enabled;
        c.SingleLine = true;
        c.TimestampFormat = "yyyy-MM-dd HH:mm:ss ";
    });

2. Debug Logging

Configure logging to debug output (useful for unit tests and debugging):

var log = StaticLogManagerSetup.ConfigureForDebugLogging(LogLevel.Debug);

log.Debug("This will appear in debug output");

3. File Logging

Simple file logging with optional rolling files:

var log = StaticLogManagerSetup.ConfigureForFileLogging(
    minLevel: LogLevel.Information,
    filePath: "app.log");

log.Info("This will be written to app.log");

With rolling file options:

var options = new FileLoggerOptions
{
    Append = true,
    FileSizeLimitBytes = 10 * 1024 * 1024,  // 10 MB
    MaxRollingFiles = 5  // Keep up to 5 log files
};

var log = StaticLogManagerSetup.ConfigureForFileLogging(
    minLevel: LogLevel.Information,
    filePath: "app.log",
    options: options);

4. Configuration from appsettings.json

Load logging configuration from your appsettings.json file:

var log = StaticLogManagerSetup.FromAppSettings();

// Or specify custom paths
var log = StaticLogManagerSetup.FromAppSettings(
    configRoot: "Logging",
    appSettings: "appsettings.json");

Example appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "System": "Warning",
      "Microsoft": "Warning"
    },
    "Console": {
      "IncludeScopes": true
    },
    "Debug": { },
    "File": {
      "Path": "logs/app.log",
      "Append": true,
      "MinLevel": "Information",
      "FileSizeLimitBytes": 10485760,
      "MaxRollingFiles": 5
    }
  }
}

👉 Include "Console", "Debug", or "File" sections to enable those providers.

5. Custom IConfiguration

Use with a custom configuration source:

var config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .AddJsonFile($"appsettings.{environment}.json", optional: true)
    .Build();

var log = StaticLogManagerSetup.FromAppSettings(config, "Logging");

6. Azure Functions Single-Thread Logging

For Azure Functions where you're passed an ILogger:

public class MyFunction
{
    [FunctionName("MyFunction")]
    public async Task Run(
        [TimerTrigger("0 */5 * * * *")] TimerInfo timer,
        ILogger logger)
    {
        // Configure Plinth to use the Azure Functions logger
        StaticLogManagerSetup.ConfigureForSingleThread(logger);

        // Now all Plinth components will use the Azure Functions logger
        var myService = new MyService();
        await myService.DoWork();
    }
}

public class MyService
{
    private static readonly ILogger log = StaticLogManager.GetLogger();

    public async Task DoWork()
    {
        log.Info("This will log through Azure Functions logger");
    }
}

Or with ILoggerFactory:

public class MyFunction
{
    private readonly ILoggerFactory _loggerFactory;

    public MyFunction(ILoggerFactory loggerFactory)
    {
        _loggerFactory = loggerFactory;
    }

    [FunctionName("MyFunction")]
    public async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo timer)
    {
        StaticLogManagerSetup.ConfigureForSingleThread(_loggerFactory);

        // All Plinth components can now log
        var myService = new MyService();
        await myService.DoWork();
    }
}

FileLoggerOptions

Configure file logging behavior:

public class FileLoggerOptions
{
    // Append to existing file (true) or overwrite (false)
    public bool Append { get; set; } = true;

    // Enable rolling files when file reaches this size (0 = disabled)
    public long FileSizeLimitBytes { get; set; } = 0;

    // Maximum number of rolling files to keep (0 = unlimited)
    public int MaxRollingFiles { get; set; } = 0;
}

Rolling File Behavior

When FileSizeLimitBytes is set:

  • Logger creates new files when the limit is reached
  • Files are named: app.log, app1.log, app2.log, etc.

When MaxRollingFiles is also set:

  • Logger reuses old files after reaching the limit
  • Example with MaxRollingFiles = 3: creates app.log, app1.log, app2.log, then overwrites app.log

Using with Plinth Ecosystem

All loggers configured with StaticLogManagerSetup work seamlessly with the Plinth ecosystem:

using Plinth.Logging.Host;

class Program
{
    static void Main()
    {
        var log = StaticLogManagerSetup.ConfigureForConsoleLogging();

        log.Info("Application started");

        // Use Plinth's logging extensions
        using (log.LogExecTiming("Initialization"))
        {
            // Timed code block
            Initialize();
        }

        log.Info("Application ready");
    }
}

Best Practices

  1. Choose the Right Logger

    • Use Console logging for development and simple CLI tools
    • Use File logging for Windows services and simple applications
    • Use NLog (via Plinth.Logging.NLog) for production applications with complex logging needs
    • Use Debug logging only for unit tests and debugging
  2. Azure Functions

    • Always use ConfigureForSingleThread() to integrate with Azure Functions logging
    • This ensures logs appear in Application Insights and the Azure Portal
  3. Configuration

    • Use appsettings.json for production deployments
    • Different environments can have different logging levels
    • File logging should use rolling files to prevent disk space issues
  4. Log Levels

    • Use Information as the default minimum level for production
    • Use Debug for development environments
    • Avoid Trace in production (too verbose)
  5. Rolling Files

    • Always set MaxRollingFiles when using FileSizeLimitBytes
    • Typical values: 10 MB per file, keep 10 files (100 MB total)
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Plinth.Logging.Host:

Package Downloads
Plinth.AzureFunction

Plinth Utilities for Azure Functions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.1 279 12/11/2025
1.8.0 468 11/13/2025
1.8.0-b211.72089fd9 280 11/12/2025
1.7.4 3,525 8/6/2025
1.7.3 170 8/2/2025
1.7.2 1,759 3/16/2025
1.7.1 617 12/12/2024
1.7.0 303 11/12/2024
1.6.6 1,002 11/8/2024
1.6.5 663 8/31/2024
1.6.4 656 8/2/2024
1.6.3 1,802 5/15/2024
1.6.2 559 2/16/2024
1.6.1 779 1/5/2024
1.6.0 367 11/30/2023
1.5.10-b186.aca976b4 176 11/30/2023
1.5.9 328 11/29/2023
1.5.9-b174.64153841 933 11/23/2023
1.5.9-b172.dfc6e7bd 194 11/17/2023
1.5.9-b171.4e2b92e2 232 11/4/2023
Loading failed

net10.0 support