serilog-mssql /serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL

★ 300⑂ 145👁 19⑃ 383● 307▤ 48
C#Apache-2.0Created 2015-02-22
Download: v10.0.0v10.0.0 ↓10.0.02026-05-22
300
stars
145
forks
19
watchers
383
prs
307
issues
48
releases

README

Serilog.Sinks.MSSqlServer !Build & Test 

A Serilog sink that writes events to Microsoft SQL Server. This sink will write the log event data to a table and can optionally also store the properties inside an XML or JSON column so they can be queried. Important properties can also be written to their own separate columns.

Package - Serilog.Sinks.MSSqlServer
| Minimum Platforms - .NET Framework 4.6.2, .NET 8.0, .NET Standard 2.0

 Topics

 Quick Start
 Sink Configuration
 Audit Sink Configuration
 Table Definition
 MSSqlServerSinkOptions Object
 ColumnOptions Object
 SqlColumn Objects
 Standard Columns
 Custom Property Columns
 External Configuration Syntax
 Troubleshooting
 Querying Property Data
 Breaking Changes
 Deprecated Features

 Quick Start

The most basic minimalistic sink initialization is done like this.

csharp
Log.Logger = new LoggerConfiguration()
    .WriteTo
    .MSSqlServer(
        connectionString: "Server=localhost;Database=LogDb;Integrated Security=SSPI;",
        sinkOptions: new MSSqlServerSinkOptions { TableName = "LogEvents" })
    .CreateLogger();


 Sample Programs

There is a set of small and simple sample programs provided with the source code in the sample directory. They demonstrate different ways to initialize the sink by code and configuration for different target frameworks.

 Sink Configuration

The sink can be configured completely through code, by using configuration files (or other types of configuration providers), a combination of both, or by using the various Serilog configuration packages. There are two configuration considerations: configuring the sink itself, and configuring the table used by the sink. The sink is configured with a typical Serilog WriteTo configuration method (or AuditTo, or similar variations). Settings for the sink are configured using a MSSqlServerSinkOptions object passed to the configuration method. The table is configured with an optional ColumnOptions object passed to the configuration method.

All sink configuration methods accept the following arguments, though not necessarily in this order. Use of named arguments is strongly recommended. Some platform targets have additional arguments.

 connectionString
 sinkOptions
 columnOptions
 restrictedToMinimumLevel
 formatProvider
 logEventFormatter

 Basic Arguments

At minimum, connectionString and MSSqlServerSinkOptions.TableName are required. If you are using an external configuration source such as an XML file or JSON file, you can use a named connection string instead of providing the full "raw" connection string.

All properties in the MSSqlServerSinkOptions object are discussed in the MSSqlServerSinkOptions Object topic.

Table configuration with the optional ColumnOptions object is a lengthy subject discussed in the ColumnOptions Object topic and other related topics.

Like other sinks, restrictedToMinimumLevel controls the LogEventLevel messages that are processed by this sink. This parameter is ignored if the property LevelS

Top issues

Discussions

Latest release

v10.0.0 v10.0.0 2026-05-22
Updated SqlClient from 6 to 7 including breaking changes around Azure Entra Id authentication. (thanks to @david-brink-talogy for Azure auth testing)
 Updated minimum SDK to 10.0.7 because of CVEs in .NET
 Replaced FluentAssertions with AwesomeAssertions for license reasons
 Updated other dependencies

Snapshot: 2026-11-16T23:08:42Z · Data license Apache-2.0 · JSON