![]() |
VOOZH | about |
dotnet add package Oakrey.Applications.CustomLogging --version 3.0.5
NuGet\Install-Package Oakrey.Applications.CustomLogging -Version 3.0.5
<PackageReference Include="Oakrey.Applications.CustomLogging" Version="3.0.5" />
<PackageVersion Include="Oakrey.Applications.CustomLogging" Version="3.0.5" />Directory.Packages.props
<PackageReference Include="Oakrey.Applications.CustomLogging" />Project file
paket add Oakrey.Applications.CustomLogging --version 3.0.5
#r "nuget: Oakrey.Applications.CustomLogging, 3.0.5"
#:package Oakrey.Applications.CustomLogging@3.0.5
#addin nuget:?package=Oakrey.Applications.CustomLogging&version=3.0.5Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.CustomLogging&version=3.0.5Install as a Cake Tool
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.
CustomLoggerBroadcast fans out every log call to any number of ICustomLogConsumer receiversLogMessage record carries level, message, caller source, indent depth, and timestampStartLog / StopLog / ClearLog control on every consumerIncreaseIndent / DecreaseIndent for structured hierarchical outputIName context item to all active consumersCustomLoggerViewModel exposes ObservableCollection<LogMessage> and INotifyPropertyChanged for direct XAML bindingICustomLoggerFilePathProvider abstracts file naming; DocumentsCustomFilePathProvider writes date-stamped .txt files to My Documents\CustomLogsclassDiagram
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 entriesICustomLogConsumer � the interface implemented by each logging engineCustomLoggerBroadcast � bridges the two, routing every ICustomLogger call to all registered consumersnet10.0-windows target; WPF types in CustomLoggerViewModel)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
// 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();
Bind the CustomLoggerViewModel directly in XAML:
<ListView ItemsSource="{Binding LogMessages}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Message}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
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");
}
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) { }
}
| 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. |
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.Oakrey.Collections (for IName and ForEach), Oakrey.Files (for FileNameSource / FileNamingPolicy).This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 net10.0-windows7.0 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.