Cirreum.Logging.Deferred 1.0.106

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

Cirreum.Logging.Deferred

NuGet Version NuGet Downloads GitHub Release

Provides deferred logging capabilities for early application setup and configuration phases where the logging infrastructure isn't yet available

Overview

During application startup, you often need to log important information before the dependency injection container and logging infrastructure are fully configured. This library allows you to queue log messages early in the application lifecycle and flush them to the actual logger once it becomes available.

Features

  • Thread-safe logging: Queue log messages from any thread during startup
  • Scope preservation: Maintains logging scopes across deferred operations
  • All log levels: Supports Debug, Information, Warning, Error, Critical, and Trace levels
  • Easy integration: Simple extension method to flush queued logs to any ILogger
  • Startup task support: Works seamlessly with startup task patterns

Installation

dotnet add package Cirreum.Logging.Deferred

Usage

Basic Usage

using Cirreum.Logging.Deferred;

// Create a deferred logger early in your application
var deferredLogger = Logger.CreateDeferredLogger();

// Queue log messages before logging infrastructure is ready
deferredLogger.LogInformation("Application starting...");
deferredLogger.LogInformation("Loading configuration from {ConfigPath}", configPath);

// Use scopes just like with regular logging
using (deferredLogger.BeginScope("Service Registration"))
{
    deferredLogger.LogInformation("Registering service {ServiceName}", serviceName);
    deferredLogger.LogDebug("Service configuration: {@Config}", config);
}

// Later, when your logging infrastructure is available
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
logger.FlushDeferredLogs(); // All queued messages are now logged

Integration with Startup Tasks

For ASP.NET Core applications, you can use a startup task to automatically flush deferred logs:

namespace MyApp.StartupTasks;

using Cirreum.Logging.Deferred;

internal class FlushDeferredLogs(
    IHostApplicationLifetime lifetime,
    ILogger<FlushDeferredLogs> logger)
    : IStartupTask 
{
    public int Order => int.MaxValue; // Run last
    
    public ValueTask ExecuteAsync() 
    {
        lifetime.ApplicationStarted.Register(HandleApplicationStarted);
        return ValueTask.CompletedTask;
    }
    
    private void HandleApplicationStarted() 
    {
        logger.FlushDeferredLogs();
    }
}

Checking for Errors During Startup

You can also inspect the deferred log queue to check for errors that occurred during startup:

// Check if any errors were logged during startup
if (Logger.HasErrors())
{
    var errors = Logger.GetErrors();
    foreach (var error in errors)
    {
        Console.WriteLine($"Startup error: {error}");
    }
}

// Get all entries of a specific level
var warnings = Logger.GetAll(LogLevel.Warning);
foreach (var (level, message) in warnings)
{
    Console.WriteLine($"{level}: {message}");
}

// Get all logged entries
var allEntries = Logger.GetAll();

API Reference

IDeferredLogger Interface

public interface IDeferredLogger 
{
    IDisposable BeginScope<TState>(TState state) where TState : notnull;
    void LogDebug(string message, params object[] args);
    void LogInformation(string message, params object[] args);
    void LogWarning(string message, params object[] args);
    void LogError(string message, params object[] args);
    void LogCritical(string message, params object[] args);
    void LogTrace(string message, params object[] args);
}

Logger Static Methods

public static class Logger 
{
    // Create a new deferred logger instance
    public static IDeferredLogger CreateDeferredLogger();
    
    // Check for specific log levels
    public static bool HasErrors();
    public static bool HasEntries(LogLevel level);
    
    // Retrieve logged messages
    public static IEnumerable<string> GetErrors();
    public static IEnumerable<(LogLevel Level, string Message)> GetAll(LogLevel level);
    public static IEnumerable<(LogLevel Level, string Message)> GetAll();
}

Extension Methods

public static class DeferredLoggerExtensions 
{
    // Flush all queued deferred logs to the provided logger
    public static void FlushDeferredLogs(this ILogger logger);
}

How It Works

  1. Queuing Phase: During application startup, log messages are queued in memory along with their metadata (level, message template, arguments, and active scopes)

  2. Flushing Phase: Once the logging infrastructure is available, call FlushDeferredLogs() to replay all queued messages through the actual logger

  3. Scope Preservation: Any logging scopes active when messages were queued are recreated during the flush operation

Thread Safety

The library is designed to be thread-safe for typical startup scenarios where multiple initialization tasks might be logging concurrently.

Contributing

This package is part of the Cirreum ecosystem. Follow the established patterns when contributing new features or provider implementations.

Product Compatible and additional computed target framework versions.
.NET 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 (5)

Showing the top 5 NuGet packages that depend on Cirreum.Logging.Deferred:

Package Downloads
Cirreum.Runtime.Server

The Cirreum Runtime for Servers.

Cirreum.Runtime.Serverless

The Cirreum Runtime Serverless.

Cirreum.Runtime.AuthorizationProvider

The Cirreum Authorization Provider for the Cirreum Runtime Server.

Cirreum.Runtime.ServiceProvider

The Cirreum ServiceProvider for the Cirreum Runtime Server.

Cirreum.Runtime.SecretsProvider

The Cirreum SecertsProvider for the Cirreum Runtime Server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.106 507 1/21/2026
1.0.105 903 12/20/2025
1.0.104 402 12/19/2025
1.0.103 367 12/16/2025
1.0.102 691 11/11/2025
1.0.101 258 11/11/2025
1.0.100 147 11/7/2025