Oakrey.Applications.CustomLogging 3.0.3

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

Oakrey.Applications.CustomLogging

A flexible and extensible .NET logging library. It decouples the logging API from concrete logging destinations, supports broadcasting to multiple receivers simultaneously, and provides a ready-to-use WPF ViewModel for in-memory log binding.

Main features

  • Multiple logging engines � console (color-coded), debug output, file, and in-memory
  • BroadcastingCustomLoggerBroadcast fans out every log call to any number of ICustomLogConsumer receivers
  • Structured log entriesLogMessage record carries level, message, caller source, indent depth, and timestamp
  • Log lifecycle � explicit StartLog / StopLog / ClearLog control on every consumer
  • IndentationIncreaseIndent / DecreaseIndent for structured hierarchical output
  • Contextual logging � attach an IName context item to all active consumers
  • WPF ViewModelCustomLoggerViewModel exposes ObservableCollection<LogMessage> and INotifyPropertyChanged for direct XAML binding
  • File path customizationICustomLoggerFilePathProvider abstracts file naming; DocumentsCustomFilePathProvider writes date-stamped .txt files to My Documents\CustomLogs

Architecture

classDiagram
    class ICustomLogger {
        +LogInfo()
        +LogWarning()
        +LogError()
        +StartLog()
        +StopLog()
        +ClearLog()
        +IncreaseIndent()
        +DecreaseIndent()
        +SetCurrentContextItem()
    }

    class ICustomLogConsumer {
        +Log(LogMessage)
        +StartLog()
        +StopLog()
        +ClearLog()
        +SetCurrentContextItem()
    }

    class CustomLoggerBroadcast {
        -IEnumerable~ICustomLogConsumer~ receivers
    }

    ICustomLogger <|.. CustomLoggerBroadcast
    CustomLoggerBroadcast --> ICustomLogConsumer : fans out to
    ICustomLogConsumer <|.. ConsoleCustomLogger
    ICustomLogConsumer <|.. FileCustomLogger
    ICustomLogConsumer <|.. DebugCustomLogger
    ICustomLogConsumer <|.. CustomLoggerViewModel

The key design split:

  • ICustomLogger � the interface used by application code to emit log entries
  • ICustomLogConsumer � the interface implemented by each logging engine
  • CustomLoggerBroadcast � bridges the two, routing every ICustomLogger call to all registered consumers

Requirements

  • .NET 10 or higher
  • Windows (due to net10.0-windows target; WPF types in CustomLoggerViewModel)

Installation

NuGet Package Manager

Search for Oakrey.Applications.CustomLogging in Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

.NET CLI

dotnet add package Oakrey.Applications.CustomLogging

Package Manager Console

Install-Package Oakrey.Applications.CustomLogging

Example usage

Basic broadcast setup

// Compose consumers
CustomLoggerViewModel viewModel = new();
FileCustomLogger fileLogger = new(new DocumentsCustomFilePathProvider());
ConsoleCustomLogger consoleLogger = new();

// Create broadcast
ICustomLogger logger = new CustomLoggerBroadcast([viewModel, fileLogger, consoleLogger]);

// Use
logger.StartLog("MySession");
logger.LogInfo("Application started");

logger.IncreaseIndent();
logger.LogWarning("Configuration value missing, using default");
logger.DecreaseIndent();

logger.LogError("Unhandled exception occurred");
logger.StopLog();

WPF binding

Bind the CustomLoggerViewModel directly in XAML:

<ListView ItemsSource="{Binding LogMessages}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Message}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Custom file path provider

Implement ICustomLoggerFilePathProvider to control where and how log files are named:

public class AppFilePathProvider : ICustomLoggerFilePathProvider
{
    public DirectoryInfo GetDirectoryPath() => new(@"C:\Logs\MyApp");
    public FileInfo GetFileInfo() => new($@"C:\Logs\MyApp\log_{DateTime.Now:yyyyMMdd}.txt");
}

Custom consumer

Implement ICustomLogConsumer to add any new logging destination:

public class DatabaseLogConsumer : ICustomLogConsumer
{
    public void Log(LogMessage message) { /* insert to DB */ }
    public void StartLog(string name) { }
    public void StopLog() { }
    public void ClearLog() { }
    public void SetCurrentContextItem(IName item) { }
}

Configuration

Type Purpose
DocumentsCustomFilePathProvider Default file path provider. Writes date-stamped .txt files to %USERPROFILE%\Documents\CustomLogs.
ICustomLoggerFilePathProvider Implement to override file location and naming strategy.

Development notes

  • FileCustomLogger is IDisposable. Dispose it (or call StopLog) to flush and close the underlying FileStream.
  • CustomLoggerBroadcast tracks a single shared indent level and propagates it to every consumer via LogMessage.IndentLevel.
  • [CallerMemberName] is used on source parameters so the calling method name is captured automatically without explicit argument passing.
  • Dependencies: Oakrey.Collections (for IName and ForEach), Oakrey.Files (for FileNameSource / FileNamingPolicy).

Project information

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
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
3.0.3 38 5/15/2026
3.0.2 116 3/13/2026
3.0.1 106 2/11/2026
3.0.0 449 11/18/2025
2.0.1 224 9/29/2025
2.0.0 249 8/4/2025
1.1.0 467 7/25/2025
1.0.0 292 4/17/2025