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
<PackageReference Include="Plinth.Logging.Host" Version="1.8.1" />
<PackageVersion Include="Plinth.Logging.Host" Version="1.8.1" />
<PackageReference Include="Plinth.Logging.Host" />
paket add Plinth.Logging.Host --version 1.8.1
#r "nuget: Plinth.Logging.Host, 1.8.1"
#:package Plinth.Logging.Host@1.8.1
#addin nuget:?package=Plinth.Logging.Host&version=1.8.1
#tool nuget:?package=Plinth.Logging.Host&version=1.8.1
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: createsapp.log,app1.log,app2.log, then overwritesapp.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
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
Azure Functions
- Always use
ConfigureForSingleThread()to integrate with Azure Functions logging - This ensures logs appear in Application Insights and the Azure Portal
- Always use
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
Log Levels
- Use
Informationas the default minimum level for production - Use
Debugfor development environments - Avoid
Tracein production (too verbose)
- Use
Rolling Files
- Always set
MaxRollingFileswhen usingFileSizeLimitBytes - Typical values: 10 MB per file, keep 10 files (100 MB total)
- Always set
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.Logging.Debug (>= 10.0.0)
- Plinth.Common (>= 1.8.1)
-
net8.0
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.Logging.Debug (>= 10.0.0)
- Plinth.Common (>= 1.8.1)
- System.Text.Json (>= 10.0.0)
-
net9.0
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.Logging.Debug (>= 10.0.0)
- Plinth.Common (>= 1.8.1)
- System.Text.Json (>= 10.0.0)
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 |
net10.0 support