Serilog.Sinks.SQLite 7.0.0-dev

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

Serilog.Sinks.SQLite

CI

A lightweight, high-performance Serilog sink that writes to a SQLite database.

Getting started

Install Serilog.Sinks.SQLite from NuGet:

Install-Package Serilog.Sinks.SQLite

Configure the logger with WriteTo.SQLite():

var logger = new LoggerConfiguration()
    .WriteTo.SQLite(@"Logs\log.db")
    .CreateLogger();

logger.Information("This informational message will be written to SQLite database");

Configuration

.WriteTo.SQLite(
    sqliteDbPath:       "Logs/log.db",
    tableName:          "Logs",
    storeTimestampInUtc: false,
    retentionPeriod:    TimeSpan.FromDays(7),     // default null (no expiry)
    batchSize:          100,                       // 1..1000
    maxDatabaseSize:    10,                        // MB, capped at ~20 GB
    rollOver:           true,                      // create sibling DB when full
    journalMode:        SqliteJournalMode.Wal)     // see notes below

Journal mode

Default is WAL (write-ahead log) — crash-safe with concurrent readers. WAL is persisted in the database file, so the first run against an older database converts it. To opt out of WAL, set journalMode: SqliteJournalMode.Memory (fast, but corrupts on crash) or Delete (legacy default).

Buffer overflow

The sink holds events in a 100 000-entry in-memory queue while batches are being flushed. When the queue fills (slow disk, stuck writer), additional events are dropped and the running drop count is reported through Serilog's SelfLog at 1, 1000, 2000, … events.

Roll-over

When the database reaches maxDatabaseSize, the sink uses VACUUM INTO to produce an atomic sibling backup named <name>-yyyyMMdd_HHmmss.ff-<guid>.db, then truncates and reuses the original file. Sidecar WAL contents are captured. Disable with rollOver: false to instead drop overflowing batches.

XML <appSettings> configuration

To use the SQLite sink with the Serilog.Settings.AppSettings package:

Install-Package Serilog.Settings.AppSettings

In your code:

var logger = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    .CreateLogger();

In App.config / Web.config:

<appSettings>
    <add key="serilog:using:SQLite" value="Serilog.Sinks.SQLite"/>
    <add key="serilog:write-to:SQLite.sqliteDbPath" value="Logs\log.db"/>
    <add key="serilog:write-to:SQLite.tableName" value="Logs"/>
    <add key="serilog:write-to:SQLite.storeTimestampInUtc" value="true"/>
</appSettings>

Performance

The sink buffers events internally and flushes to SQLite in batches on a dedicated thread. Properties are serialised once outside the database transaction, so commit latency is bounded by I/O rather than JSON work. When a retentionPeriod is configured, the sink also creates IX_<table>_Timestamp so the periodic delete is O(log n) instead of a full scan.

Breaking changes in 7.0

  • Targets netstandard2.0 + net8.0; net7.0 dropped.
  • Serilog 4.x required.
  • Storage layer switched to Microsoft.Data.Sqlite (was System.Data.SQLite). True cross-platform — no native interop quirks on Linux/macOS.
  • Properties JSON now produced by System.Text.Json (was Newtonsoft.Json). Output uses the relaxed encoder so payloads stay human-readable, but <, >, &, ' will not be escaped to \u00xx anymore.
  • Exception and Properties columns store NULL when the event has none (previously empty strings).
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on Serilog.Sinks.SQLite:

Package Downloads
Devon4Net.Infrastructure.Logger

devon4net logger library

Afx.Zb.Common

常用公共类库

Plugga.Core

Plugga.Core lets you quickly create modular ASP .Net Core applications searching, loading and configuring any "pluggable" component. Pluggable components are a little set of commonly used objects as Controllers, DbContexts, Razor Pages, SignalR Hubs, HostedServices, static assets and, of course, your own component objects.

Shoremem.Core

Package Description

QCommon.SeriLog

支持SEQ

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Serilog.Sinks.SQLite:

Repository Stars
Warewolf-ESB/Warewolf
Effortless Microservice Design and Integration. This repository includes the code-base for the Warewolf Studio and Server.
serilog-contrib/serilog-ui
Simple Serilog log viewer UI for several sinks.
Version Downloads Last Updated
7.0.0-dev 33 5/30/2026
6.0.0 264,287 5/1/2023
5.5.0 156,207 7/1/2022
5.0.0 190,666 11/26/2019
5.0.0-dev-00086 1,474 5/31/2019
5.0.0-dev-00082 1,026 3/18/2019
4.5.0 60,956 1/2/2019
4.0.0 12,701 7/3/2018
3.9.1 1,768 5/31/2018
3.9.0 2,078 1/18/2018
Loading failed