Oakrey.Applications.Log
4.0.4
dotnet add package Oakrey.Applications.Log --version 4.0.4
NuGet\Install-Package Oakrey.Applications.Log -Version 4.0.4
<PackageReference Include="Oakrey.Applications.Log" Version="4.0.4" />
<PackageVersion Include="Oakrey.Applications.Log" Version="4.0.4" />
<PackageReference Include="Oakrey.Applications.Log" />
paket add Oakrey.Applications.Log --version 4.0.4
#r "nuget: Oakrey.Applications.Log, 4.0.4"
#:package Oakrey.Applications.Log@4.0.4
#addin nuget:?package=Oakrey.Applications.Log&version=4.0.4
#tool nuget:?package=Oakrey.Applications.Log&version=4.0.4
Oakrey.Applications.Log
A .NET 10 library that integrates Oakrey logging into Windows applications via IServiceCollection extension methods. It provides a WpfQueueLogger-backed view model for real-time UI log visualization, settings-persisted log level filtering, and a preloadable cleanup service that removes log files older than 7 days.
Main features
ConfigureLoggingServices� initializesLoggerFactorybasic loggers and registersILogger<T>/LoggerProxy<T>as singletons in the DI container.ConfigureLogViewServices� registers aWpfQueueLoggersingleton (queue capacity 100) and a transientLogViewModelfor WPF binding.LogViewModel� bindable view model exposingWpfQueueLogger, a settings-persistedDisplayLogLevel(Level.Informationdefault), and a settings-persistedVerticalOffsetValue. Includes a design-time constructor that pre-populates sample log entries.LogFileCleanupService� implementsIPreLoadableandIDisposable. OnPreload(), deletes.logfiles older than 7 days fromDocuments\<AppName>\Logs. Reports failures asPreLoadingExceptionviaIObservable<PreLoadingException>backed by aReplaySubject.ILogConfig� interface for decoupled access toDisplayLogLevelandVerticalOffsetValue.
Architecture
classDiagram
class LoggingConfigurationExtension {
+AddOakreyLogging(IServiceCollection) IServiceCollection
+ConfigureLoggingServices(IServiceCollection) IServiceCollection
+ConfigureLogViewServices(IServiceCollection) IServiceCollection
}
class LogViewModel {
+WpfLogger : WpfQueueLogger
+DisplayLogLevel : Level
+VerticalOffsetValue : double
}
class LogFileCleanupService {
+Preload(CancellationToken) Task
+Subscribe(IObserver) IDisposable
+Dispose()
}
class ILogConfig {
<<interface>>
+DisplayLogLevel : Level
+VerticalOffsetValue : double
+GetValue~T~(string) T
}
class ILogFileCleanupService {
<<interface>>
}
LogViewModel ..|> INotifyPropertyChanged
LogViewModel ..|> ILogConfig
LogFileCleanupService ..|> ILogFileCleanupService
LogFileCleanupService ..|> IPreLoadable
LogFileCleanupService ..|> IDisposable
LoggingConfigurationExtension --> LogViewModel : registers
LoggingConfigurationExtension --> WpfQueueLogger : registers
Requirements
- .NET 10 (net10.0-windows)
- Windows
- Dependencies:
Oakrey.Applications.Settings,Oakrey.Log,Oakrey.Log.Windows
Installation
.NET CLI
dotnet add package Oakrey.Applications.Log
Package Manager Console
Install-Package Oakrey.Applications.Log
NuGet Package Manager in Visual Studio
Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution, search for Oakrey.Applications.Log, and install.
Usage
Registering logging services
Call both methods during application startup, typically in your DI composition root:
services
.ConfigureLoggingServices() // registers ILogger<T>, initializes LoggerFactory
.ConfigureLogViewServices(); // registers WpfQueueLogger + LogViewModel
AddOakreyLogging() is also available as a standalone call when you only need ILogger<T> registration without reinitializing LoggerFactory.
Binding LogViewModel in WPF
<ItemsControl ItemsSource="{Binding WpfLogger.Entries}">
...
</ItemsControl>
<ComboBox SelectedItem="{Binding DisplayLogLevel}" />
// inject via DI
public LogView(LogViewModel viewModel)
{
DataContext = viewModel;
InitializeComponent();
}
Registering the cleanup service
services.AddSingleton<ILogFileCleanupService, LogFileCleanupService>();
Then call Preload during application startup (or via the IPreLoadable pipeline):
await logFileCleanupService.Preload(cancellationToken);
Subscribe to failures if you want to surface them in the UI:
logFileCleanupService.Subscribe(ex =>
{
// ex.Message, ex.Detail, ex.InnerException available
});
Using ILogConfig
public class MyService(ILogConfig logConfig)
{
public void Apply()
{
Level level = logConfig.DisplayLogLevel;
}
}
Development notes
- Log file path � files are deleted from
Environment.SpecialFolder.MyDocuments\<IApplicationInfo.Name>\Logs. The application name is resolved via the injectedIApplicationInfo. - Retention period � hardcoded to 7 days (
TimeSpan(7, 0, 0, 0)). There is currently no configuration API for this value. - Design-time support �
LogViewModelhas a parameterless constructor that seeds sample entries atInformation,Debug, andErrorlevels, enabling XAML designer previews without DI. ReplaySubject�LogFileCleanupServiceusesReplaySubject<PreLoadingException>so late subscribers still receive exceptions that occurred before they subscribed. Dispose the service to release it.
Project information
| Field | Value |
|---|---|
| Package ID | Oakrey.Applications.Log |
| Author | Oakrey |
| License | MIT |
| Repository | ApplicationServices |
| Project URL | oakrey.cz |
| NuGet | Oakrey.Applications.Log |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Oakrey.Applications.Settings (>= 5.1.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.