CDS.SQLiteLogging
1.0.27
See the version list below for details.
dotnet add package CDS.SQLiteLogging --version 1.0.27
NuGet\Install-Package CDS.SQLiteLogging -Version 1.0.27
<PackageReference Include="CDS.SQLiteLogging" Version="1.0.27" />
<PackageVersion Include="CDS.SQLiteLogging" Version="1.0.27" />
<PackageReference Include="CDS.SQLiteLogging" />
paket add CDS.SQLiteLogging --version 1.0.27
#r "nuget: CDS.SQLiteLogging, 1.0.27"
#addin nuget:?package=CDS.SQLiteLogging&version=1.0.27
#tool nuget:?package=CDS.SQLiteLogging&version=1.0.27
CDS.SQLiteLogging
CDS.SQLiteLogging
CDS.SQLiteLogging is a logging library for .NET applications that uses SQLite for storing log entries. It supports batch processing, housekeeping, and integrates with the Microsoft.Extensions.Logging framework.
TODO
This is a first draft of the readme. It needs to be updated with:
- Example not using dependency injection.
- Housekeeping example
- More discussion of the features and how to use them and how this thing works!
- Log reader
- UI log viewer support
- DB browser tool and SQLite links
- Any rational for why we are doing this and what the benefits are!
- Unit tests and the little tick box thing that shows everything is passing!
Features
- Batch Processing: Efficiently writes log entries in batches to improve performance.
- Housekeeping: Automatically or manually cleans up old log entries based on configurable retention policies.
- Flexible Configuration: Easily configurable options for batching, housekeeping, and logging levels.
- Integration with Microsoft.Extensions.Logging: Seamlessly integrates with the .NET logging framework.
Installation
You can install the CDS.SQLiteLogging library via NuGet:
dotnet add package CDS.SQLiteLogging
Usage
Basic Setup for Microsoft Logging and Dependency Injection
To set up the library in a .NET application, follow these steps:
- Configure the Logger Provider:
using CDS.SQLiteLogging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// Get the path for the SQLite database file
string dbPath = GetDatabasePath();
// Create the SQLite logger provider
var sqliteLoggerProvider = MSSQLiteLoggerProvider.Create(dbPath);
// Setup dependency injection
using var serviceProvider = new ServiceCollection()
.AddLogging(builder =>
{
builder.ClearProviders();
builder.AddProvider(sqliteLoggerProvider);
builder.SetMinimumLevel(LogLevel.Trace);
})
.AddTransient<DemoService>() // a demo service for this readme!
.BuildServiceProvider();
Example database path builder:
private static string GetDatabasePath()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
nameof(CDS),
nameof(CDS.SQLiteLogging),
nameof(ConsoleTest),
$"Log_V{MSSQLiteLogger.DBSchemaVersion}.db");
}
- Using the Logger:
using Microsoft.Extensions.Logging;
namespace ConsoleTest.DISimplestDemo;
/// <summary>
/// Provides demo services for processing and logging.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="DemoService"/> class.
/// </remarks>
/// <param name="logger">The logger instance.</param>
class DemoService(ILogger<DemoService> logger)
{
/// <summary>
/// Runs the demo service.
/// </summary>
public void Run()
{
using var scope = logger.BeginScope("DemoService.Run");
logger.LogDebug("Here we go!");
DoSomeProcessing();
}
/// <summary>
/// Processes some items and logs the progress.
/// </summary>
private void DoSomeProcessing()
{
using var scope = logger.BeginScope("DemoService.DoSomeProcessing");
for (var i = 0; i < 4; i++)
{
logger.LogInformation("Processing item {ItemNumber}", i);
}
}
}
Configuration Options
Batching Options
- BatchSize: The maximum number of entries to write in a single batch.
- MaxCacheSize: The maximum number of entries to cache. Any items logged when the cache is full will be discarded.
- FlushInterval: The interval in milliseconds between cache flushes.
Housekeeping Options
- Mode: The housekeeping mode (Automatic or Manual).
- RetentionPeriod: The retention period for log entries.
- CleanupInterval: The interval between cleanup operations.
API Reference
Public Classes and Methods
- SQLiteWriter: Provides writing capabilities for SQLite logging with caching, batching, and housekeeping.
- SQLiteReader: Provides read-only access to SQLite log entries.
- BatchingOptions: Configuration options for batch processing of log entries.
- HouseKeepingOptions: Configuration options for housekeeping of log entries.
Contributing
We welcome contributions to the CDS.SQLiteLogging library. Please feel free to submit issues and pull requests on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For support or questions, please contact us via GitHub.
Attributions
<a href="https://www.flaticon.com/free-icons/log-file" title="log file icons">Log file icons created by Muhammad_Usman - Flaticon</a>
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 was computed. 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. |
.NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Newtonsoft.Json (>= 13.0.3)
- System.Collections.Immutable (>= 9.0.3)
- System.Data.SQLite (>= 1.0.119)
-
net8.0
- Microsoft.Data.Sqlite (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- Microsoft.Extensions.Logging (>= 9.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.3)
- Newtonsoft.Json (>= 13.0.3)
- System.Collections.Immutable (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.