CDS.SQLiteLogging 1.0.27

There is a newer version of this package available.
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
                    
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="CDS.SQLiteLogging" Version="1.0.27" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CDS.SQLiteLogging" Version="1.0.27" />
                    
Directory.Packages.props
<PackageReference Include="CDS.SQLiteLogging" />
                    
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 CDS.SQLiteLogging --version 1.0.27
                    
#r "nuget: CDS.SQLiteLogging, 1.0.27"
                    
#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.
#addin nuget:?package=CDS.SQLiteLogging&version=1.0.27
                    
Install CDS.SQLiteLogging as a Cake Addin
#tool nuget:?package=CDS.SQLiteLogging&version=1.0.27
                    
Install CDS.SQLiteLogging as a Cake Tool

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:

  1. 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");
}
  1. 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 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. 
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
1.1.3 145 4/6/2025
1.0.27 254 4/4/2025
1.0.25 143 4/2/2025
1.0.17 140 4/1/2025
1.0.16 142 4/1/2025
1.0.14 144 4/1/2025