CSharpEssentials.LoggerHelper.Sink.MSSqlServer
5.2.2.5
dotnet add package CSharpEssentials.LoggerHelper.Sink.MSSqlServer --version 5.2.2.5
NuGet\Install-Package CSharpEssentials.LoggerHelper.Sink.MSSqlServer -Version 5.2.2.5
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.MSSqlServer" Version="5.2.2.5" />
<PackageVersion Include="CSharpEssentials.LoggerHelper.Sink.MSSqlServer" Version="5.2.2.5" />
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.MSSqlServer" />
paket add CSharpEssentials.LoggerHelper.Sink.MSSqlServer --version 5.2.2.5
#r "nuget: CSharpEssentials.LoggerHelper.Sink.MSSqlServer, 5.2.2.5"
#:package CSharpEssentials.LoggerHelper.Sink.MSSqlServer@5.2.2.5
#addin nuget:?package=CSharpEssentials.LoggerHelper.Sink.MSSqlServer&version=5.2.2.5
#tool nuget:?package=CSharpEssentials.LoggerHelper.Sink.MSSqlServer&version=5.2.2.5
CSharpEssentials.LoggerHelper.Sink.MSSqlServer
SQL Server structured log storage with auto table creation and custom columns for CSharpEssentials.LoggerHelper.
Targets: net8.0 · net9.0 · net10.0 — Part of the CSharpEssentials.LoggerHelper ecosystem. Install only the sinks you need.
Install
dotnet add package CSharpEssentials.LoggerHelper
dotnet add package CSharpEssentials.LoggerHelper.Sink.MSSqlServer
Quick Setup — JSON
Add to appsettings.json:
{
"LoggerHelper": {
"ApplicationName": "MyApp",
"Routes": [
{ "Sink": "MSSqlServer", "Levels": ["Warning", "Error", "Fatal"] }
],
"Sinks": {
"MSSqlServer": {
"ConnectionString": "Server=.;Database=Logs;Trusted_Connection=true;TrustServerCertificate=true",
"TableName": "AppLogs",
"AutoCreateSqlTable": true,
"BatchPostingLimit": 100,
"Period": "0.00:00:10"
}
}
}
}
// Program.cs
builder.Services.AddLoggerHelper(builder.Configuration);
var app = builder.Build();
app.UseLoggerHelper(); // ← required: activates sinks and registers middleware
AutoCreateSqlTable: truecreates the table on first run if it does not already exist. Set tofalseif you manage schema migrations yourself.
Quick Setup — Fluent API
builder.Services.AddLoggerHelper(b => b
.WithApplicationName("MyApp")
.AddRoute("MSSqlServer", LogEventLevel.Warning, LogEventLevel.Error, LogEventLevel.Fatal)
.ConfigureMSSqlServer(s => {
s.ConnectionString = "Server=.;Database=Logs;Trusted_Connection=true;TrustServerCertificate=true";
s.TableName = "AppLogs";
s.AutoCreateSqlTable = true;
})
);
var app = builder.Build();
app.UseLoggerHelper(); // ← required
What You'll See
Log events are batched and inserted as rows into the configured table. Default columns created by AutoCreateSqlTable:
| Column | SQL Type | Notes |
|---|---|---|
Id |
BIGINT IDENTITY |
Primary key |
Message |
NVARCHAR(MAX) |
Rendered log message |
MessageTemplate |
NVARCHAR(MAX) |
Raw template with {placeholders} |
Level |
NVARCHAR(128) |
e.g. Warning, Error |
TimeStamp |
DATETIME |
UTC timestamp |
Exception |
NVARCHAR(MAX) |
Full exception string (nullable) |
Properties |
NVARCHAR(MAX) |
All structured properties as XML |
Custom Columns — Map Log Properties to SQL Columns
Use AdditionalColumns to promote any log property into a dedicated, queryable column.
"Sinks": {
"MSSqlServer": {
"ConnectionString": "...",
"TableName": "AppLogs",
"AdditionalColumns": [
{ "ColumnName": "TenantId", "DataType": "NVarChar", "DataLength": 100, "AllowNull": true },
{ "ColumnName": "RequestId", "DataType": "NVarChar", "DataLength": 50, "AllowNull": true },
{ "ColumnName": "UserId", "DataType": "NVarChar", "DataLength": 50, "AllowNull": true }
]
}
}
Then populate those properties at runtime using BeginScope or LogContext.PushProperty:
// Option A — BeginScope (preferred for scoped operations)
using (_logger.BeginScope(new Dictionary<string, object?> {
["TenantId"] = "acme",
["RequestId"] = HttpContext.TraceIdentifier
}))
{
_logger.LogWarning("Payment failed for order {OrderId}", orderId);
}
// Option B — LogContext (Serilog-specific)
using (Serilog.Context.LogContext.PushProperty("UserId", userId))
{
_logger.LogError("Unauthorized access attempt");
}
The
ColumnNamemust exactly match the log property name (case-insensitive). The column is created automatically whenAutoCreateSqlTable: true.
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
ConnectionString |
string |
"" |
Required. ADO.NET SQL Server connection string. |
TableName |
string |
"Logs" |
Target table name. |
SchemaName |
string |
"dbo" |
Table schema. |
AutoCreateSqlTable |
bool |
true |
Create the table on startup if it does not exist. |
BatchPostingLimit |
int |
100 |
Maximum events per batch INSERT. |
Period |
string |
"0.00:00:10" |
Flush interval in d.hh:mm:ss format. "0.00:00:10" = 10 seconds. |
AddStandardColumns |
List<string>? |
null |
Standard columns to include. Valid values: Id, Message, MessageTemplate, Level, TimeStamp, Exception, Properties, LogEvent. |
RemoveStandardColumns |
List<string>? |
null |
Standard columns to exclude (e.g. ["Properties"] to drop the XML blob). |
AdditionalColumns |
List<AdditionalColumnConfig>? |
null |
Custom columns mapped from log properties (see above). |
AdditionalColumnConfig
| Property | Type | Default | Description |
|---|---|---|---|
ColumnName |
string |
"" |
SQL column name — must match the log property name. |
DataType |
string |
"NVarChar" |
SQL type. Any SqlDbType name: NVarChar, Int, BigInt, DateTime, Bit, etc. |
AllowNull |
bool |
true |
Whether the column accepts NULL. |
DataLength |
int |
-1 |
Column length. -1 = MAX. Use a fixed length (e.g. 100) for indexed columns. |
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
| No output at all | app.UseLoggerHelper() missing |
Add it after builder.Build() |
| Table not created | Insufficient DB permissions or AutoCreateSqlTable: false |
Grant CREATE TABLE permission or create the table manually |
| Rows appear with delay | Events are batched — flushed every Period or when BatchPostingLimit is reached |
Reduce Period (e.g. "0.00:00:02") or BatchPostingLimit for faster writes |
AdditionalColumns column always NULL |
Log property name doesn't match ColumnName |
Check casing: TenantId in config ↔ ["TenantId"] in BeginScope |
TrustServerCertificate error |
SQL Server uses a self-signed certificate | Add TrustServerCertificate=true to the connection string |
Links
| 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 is compatible. 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 is compatible. 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. |
-
net10.0
- CSharpEssentials.LoggerHelper (>= 5.2.2.5)
- Serilog.Sinks.MSSqlServer (>= 8.2.0)
-
net8.0
- CSharpEssentials.LoggerHelper (>= 5.2.2.5)
- Serilog.Sinks.MSSqlServer (>= 8.2.0)
-
net9.0
- CSharpEssentials.LoggerHelper (>= 5.2.2.5)
- Serilog.Sinks.MSSqlServer (>= 8.2.0)
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 |
|---|---|---|
| 5.2.2.5 | 28 | 7/5/2026 |
| 5.2.2.4 | 28 | 7/5/2026 |
| 5.2.2.3 | 37 | 7/5/2026 |
| 5.2.2.2 | 44 | 7/5/2026 |
| 5.2.2.1 | 39 | 7/4/2026 |
| 5.2.2 | 49 | 7/3/2026 |
| 5.2.0 | 96 | 6/29/2026 |
| 5.1.1 | 102 | 6/19/2026 |
| 5.1.0 | 105 | 6/16/2026 |
| 5.0.8 | 107 | 6/13/2026 |
| 5.0.7 | 101 | 6/11/2026 |
| 5.0.6 | 93 | 6/10/2026 |
| 5.0.5 | 105 | 6/6/2026 |
| 5.0.4 | 104 | 6/5/2026 |
| 5.0.3 | 105 | 6/2/2026 |
| 5.0.2 | 107 | 6/1/2026 |
| 5.0.1 | 108 | 5/31/2026 |
| 5.0.0 | 104 | 5/31/2026 |
| 4.0.2.2 | 223 | 10/10/2025 |
| 4.0.2.1 | 259 | 9/13/2025 |