CSharpEssentials.LoggerHelper.Sink.Postgresql
5.2.2
dotnet add package CSharpEssentials.LoggerHelper.Sink.Postgresql --version 5.2.2
NuGet\Install-Package CSharpEssentials.LoggerHelper.Sink.Postgresql -Version 5.2.2
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" Version="5.2.2" />
<PackageVersion Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" Version="5.2.2" />Directory.Packages.props
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" />Project file
paket add CSharpEssentials.LoggerHelper.Sink.Postgresql --version 5.2.2
#r "nuget: CSharpEssentials.LoggerHelper.Sink.Postgresql, 5.2.2"
#:package CSharpEssentials.LoggerHelper.Sink.Postgresql@5.2.2
#addin nuget:?package=CSharpEssentials.LoggerHelper.Sink.Postgresql&version=5.2.2Install as a Cake Addin
#tool nuget:?package=CSharpEssentials.LoggerHelper.Sink.Postgresql&version=5.2.2Install as a Cake Tool
CSharpEssentials.LoggerHelper.Sink.Postgresql
PostgreSQL structured log storage with JSONB support and custom columns for CSharpEssentials.LoggerHelper.
Part of the CSharpEssentials.LoggerHelper ecosystem — install only the sinks you need.
Install
dotnet add package CSharpEssentials.LoggerHelper
dotnet add package CSharpEssentials.LoggerHelper.Sink.Postgresql
Quick Setup — JSON
{
"LoggerHelper": {
"ApplicationName": "MyApp",
"Routes": [
{ "Sink": "Postgresql", "Levels": ["Warning", "Error", "Fatal"] }
],
"Sinks": {
"Postgresql": {
"ConnectionString": "Host=localhost;Database=logs;Username=app;Password=secret",
"TableName": "app_logs",
"NeedAutoCreateTable": true
}
}
}
}
builder.Services.AddLoggerHelper(builder.Configuration);
var app = builder.Build();
app.UseLoggerHelper(); // ← required: activates sinks and registers middleware
Quick Setup — Fluent API
builder.Services.AddLoggerHelper(b => b
.WithApplicationName("MyApp")
.AddRoute("Postgresql", LogEventLevel.Warning, LogEventLevel.Error, LogEventLevel.Fatal)
.ConfigurePostgreSql(p => {
p.ConnectionString = "Host=localhost;Database=logs;Username=app;Password=secret";
p.TableName = "app_logs";
p.NeedAutoCreateTable = true;
})
);
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
ConnectionString |
string |
"" |
PostgreSQL connection string |
TableName |
string |
"logs" |
Target table name |
SchemaName |
string |
"public" |
Table schema |
NeedAutoCreateTable |
bool |
true |
Automatically create the log table |
AddAutoIncrementColumn |
bool |
false |
Add an auto-increment primary key column |
Columns |
List<PostgreSqlColumnConfig>? |
null |
Custom column definitions (overrides defaults) |
Default Columns
When Columns is omitted the sink creates this table automatically:
| Column | Writer | PostgreSQL type | Notes |
|---|---|---|---|
ApplicationName |
Single |
Text |
Value of the ApplicationName log property |
message |
Rendered |
Text |
Final rendered log message |
message_template |
Template |
Text |
Raw Serilog template with {placeholders} |
level |
Level |
Varchar |
e.g. Information, Error |
raise_date |
Timestamp |
Timestamp |
UTC timestamp of the event |
exception |
Exception |
Text |
Full exception string (nullable) |
properties |
Serialized |
Jsonb |
All structured properties as JSONB — queryable with -> operator |
MachineName |
Single |
Text |
Host name |
Action |
Single |
Text |
Custom Action property from scope |
IdTransaction |
Single |
Text |
Correlation ID from scope |
Custom Columns — Replicate or Extend the Default Schema
Use Columns to define exactly which columns the sink writes.
When Columns is present it replaces the default set entirely.
Example A — Replicating the default schema via JSON
"Sinks": {
"Postgresql": {
"ConnectionString": "Host=localhost;Database=logs;Username=app;Password=secret",
"TableName": "app_logs",
"NeedAutoCreateTable": true,
"Columns": [
{ "Name": "ApplicationName", "Writer": "Single", "Type": "Text", "Property": "ApplicationName" },
{ "Name": "message", "Writer": "Rendered", "Type": "Text" },
{ "Name": "message_template","Writer": "Template", "Type": "Text" },
{ "Name": "level", "Writer": "Level", "Type": "Varchar" },
{ "Name": "raise_date", "Writer": "Timestamp", "Type": "Timestamp" },
{ "Name": "exception", "Writer": "Exception", "Type": "Text" },
{ "Name": "properties", "Writer": "Serialized","Type": "Jsonb" },
{ "Name": "MachineName", "Writer": "Single", "Type": "Text", "Property": "MachineName" },
{ "Name": "Action", "Writer": "Single", "Type": "Text", "Property": "Action" },
{ "Name": "IdTransaction", "Writer": "Single", "Type": "Text", "Property": "IdTransaction" }
]
}
}
Example B — Custom schema with application-specific properties
Add only the columns you need, including custom properties pushed via BeginScope:
"Columns": [
{ "Name": "message", "Writer": "Rendered", "Type": "Text" },
{ "Name": "level", "Writer": "Level", "Type": "Varchar" },
{ "Name": "raise_date", "Writer": "Timestamp", "Type": "Timestamp" },
{ "Name": "exception", "Writer": "Exception", "Type": "Text" },
{ "Name": "properties", "Writer": "Serialized","Type": "Jsonb" },
{ "Name": "TenantId", "Writer": "Single", "Type": "Text", "Property": "TenantId" },
{ "Name": "UserId", "Writer": "Single", "Type": "Text", "Property": "UserId" },
{ "Name": "RequestId", "Writer": "Single", "Type": "Text", "Property": "RequestId" }
]
Populate the custom properties at runtime with BeginScope:
using (_logger.BeginScope(new Dictionary<string, object?> {
["TenantId"] = "acme",
["UserId"] = "usr_99",
["RequestId"] = HttpContext.TraceIdentifier
}))
{
_logger.LogWarning("Payment failed for order {OrderId}", orderId);
}
Propertyis required only forWriter: "Single"when the column name differs from the Serilog property name. IfNameand the property name match, you can omitProperty.
PostgreSqlColumnConfig reference
| Property | Type | Default | Description |
|---|---|---|---|
Name |
string |
"" |
Column name in the database table |
Writer |
string |
"Single" |
How the value is extracted — see table below |
Type |
string |
"Text" |
PostgreSQL column type: Text, Jsonb, Varchar, Timestamp |
Property |
string? |
null |
Serilog property name for Single writer (defaults to Name) |
Writer values:
| Writer | Maps to | Use for |
|---|---|---|
Rendered |
Rendered log message | Human-readable message |
Template |
Raw message template | Grouping / searching by template |
Level |
Log level | Information, Warning, Error, Fatal |
Timestamp |
Event UTC timestamp | Time-range queries |
Exception |
Full exception string | Error analysis |
Serialized |
All properties as JSON | Catch-all JSONB blob |
Properties |
All properties (key-value) | Alternative to Serialized |
Single |
One named property | Custom scope/enricher values |
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)
- Microsoft.NETCore.Jit (>= 2.0.8)
- Npgsql (>= 10.0.3)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.0)
-
net8.0
- CSharpEssentials.LoggerHelper (>= 5.2.2)
- Microsoft.NETCore.Jit (>= 2.0.8)
- Npgsql (>= 10.0.3)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.0)
-
net9.0
- CSharpEssentials.LoggerHelper (>= 5.2.2)
- Microsoft.NETCore.Jit (>= 2.0.8)
- Npgsql (>= 10.0.3)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.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 | 0 | 7/3/2026 |
| 5.2.0 | 96 | 6/29/2026 |
| 5.1.1 | 106 | 6/19/2026 |
| 5.1.0 | 98 | 6/16/2026 |
| 5.0.8 | 101 | 6/13/2026 |
| 5.0.7 | 106 | 6/11/2026 |
| 5.0.6 | 106 | 6/10/2026 |
| 5.0.5 | 102 | 6/6/2026 |
| 5.0.4 | 101 | 6/5/2026 |
| 5.0.3 | 108 | 6/2/2026 |
| 5.0.2 | 111 | 6/1/2026 |
| 5.0.1 | 92 | 5/31/2026 |
| 5.0.0 | 107 | 5/31/2026 |
| 4.1.4 | 132 | 3/30/2026 |
| 4.1.1 | 118 | 3/30/2026 |
| 4.1.0 | 125 | 3/27/2026 |
| 4.0.2 | 322 | 9/13/2025 |
| 4.0.0 | 344 | 8/25/2025 |
| 3.1.5 | 242 | 6/15/2025 |
| 3.1.4 | 368 | 6/12/2025 |