CSharpEssentials.LoggerHelper.Sink.Postgresql
4.1.4
dotnet add package CSharpEssentials.LoggerHelper.Sink.Postgresql --version 4.1.4
NuGet\Install-Package CSharpEssentials.LoggerHelper.Sink.Postgresql -Version 4.1.4
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" Version="4.1.4" />
<PackageVersion Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" Version="4.1.4" />
<PackageReference Include="CSharpEssentials.LoggerHelper.Sink.Postgresql" />
paket add CSharpEssentials.LoggerHelper.Sink.Postgresql --version 4.1.4
#r "nuget: CSharpEssentials.LoggerHelper.Sink.Postgresql, 4.1.4"
#:package CSharpEssentials.LoggerHelper.Sink.Postgresql@4.1.4
#addin nuget:?package=CSharpEssentials.LoggerHelper.Sink.Postgresql&version=4.1.4
#tool nuget:?package=CSharpEssentials.LoggerHelper.Sink.Postgresql&version=4.1.4
π CSharpEssentials.LoggerHelper.Sink.PostgreSQL
A flexible PostgreSQL sink for CSharpEssentials.LoggerHelper, designed to store structured logs directly in PostgreSQL with support for custom schemas, JSON fields, and automatic table creation.
Change Log ( 4.1.4 )
- Connection resilience: if PostgreSQL is unreachable at startup, the sink is skipped gracefully and the service starts normally instead of crashing.
- Fast-fail timeout: connection attempts during startup are capped at 3 seconds to avoid blocking the ASP.NET Core pipeline.
- Structured diagnostics: connection errors are classified by category (
INFRASTRUCTURE,CREDENTIALS,NETWORK_TIMEOUT,CONFIGURATION,SSL,UNKNOWN) with a human-readablehintfield aimed at system administrators. - Minimal API endpoint: a new
/api/sink-errorsendpoint exposes connection errors at runtime β see Connection diagnostics endpoint below.
π₯ Key Features
- π Native PostgreSQL integration with auto table creation.
- π Support for custom schemas and column mappings.
- π¦ Handles JSON/JSONB fields for structured data.
- β‘ Perfect for analytics, dashboards, and long-term log storage.
- π§ Works seamlessly with LoggerHelperβs level-based sink routing.
π¦ Installation
dotnet add package CSharpEssentials.LoggerHelper.Sink.PostgreSQL
Connection diagnostics endpoint
When PostgreSQL is unreachable at startup the sink is automatically skipped, the service starts normally, and the error is stored in GlobalLogger.Errors. You can expose that information via a Minimal API endpoint directly in your client Program.cs.
Why you need this
Without this endpoint, a connection failure is silent from the outside: the service runs but logs are never written to PostgreSQL. The endpoint lets you β or your monitoring system β detect the problem immediately without reading logs or restarting the service.
How to add it in your client project
Add the using and the endpoint to your Program.cs as shown below. The endpoint must be registered after app.Build().
// Program.cs
using CSharpEssentials.LoggerHelper; // required for GlobalLogger
var builder = WebApplication.CreateBuilder(args);
// 1. Register LoggerHelper β must come before app.Build()
builder.Services.AddloggerConfiguration(builder.Configuration);
// ... your other services ...
var app = builder.Build();
// ... your other middleware ...
// 2. Register the diagnostics endpoint β must come after app.Build()
app.MapGet("/api/sink-errors", () =>
{
var sinkErrors = GlobalLogger.Errors
.Where(e => e.SinkName == "SelfLog")
.OrderByDescending(e => e.Timestamp)
.Select(e => new { e.Timestamp, e.SinkName, e.ErrorMessage })
.ToList();
return sinkErrors.Count == 0
? Results.Ok(new { status = "ok", message = "No sink errors detected.", errors = sinkErrors })
: Results.Ok(new { status = "degraded", message = $"{sinkErrors.Count} sink error(s) detected.", errors = sinkErrors });
});
app.Run();
AddloggerConfigurationmust always be called beforeapp.Build().MapGet("/api/sink-errors", ...)must always be called afterapp.Build().
Response when everything is fine
{
"status": "ok",
"message": "No sink errors detected.",
"errors": []
}
Response when PostgreSQL is unreachable
{
"status": "degraded",
"message": "1 sink error(s) detected.",
"errors": [
{
"timestamp": "2026-03-30T09:39:55Z",
"sinkName": "SelfLog",
"errorMessage": "[PostgreSQL sink skipped] CATEGORY=INFRASTRUCTURE | TARGET=Host=myhost;Port=5432;Database=mydb;Username=myuser | [NpgsqlException] Exception while reading from stream | InnerException: [IOException] Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. | HINT=The PostgreSQL server is unreachable. Check that the server is running, the host/port are correct, and that no firewall is blocking port 5432. This is NOT an application bug."
}
]
}
Error categories
The CATEGORY and HINT fields inside errorMessage are intended for system administrators, not developers. Each category maps to a specific infrastructure action:
| Category | Root cause | What the sysadmin should check |
|---|---|---|
INFRASTRUCTURE |
Server down, firewall, wrong host/port | PostgreSQL service status, network route, port 5432 open |
CREDENTIALS |
Wrong username/password, pg_hba.conf |
Connection string credentials, server auth config |
NETWORK_TIMEOUT |
Server overloaded, firewall dropping packets | Server load, firewall rules (silent drop vs reject) |
CONFIGURATION |
Database does not exist | Database name in the connection string |
SSL |
TLS/certificate mismatch | SSL mode in connection string, server certificate |
UNKNOWN |
Unexpected error | Escalate full errorMessage to the development team |
All categories except
UNKNOWNindicate an infrastructure problem, not an application bug.
Demo Project
A full working demo with PostgreSQL integration is available here: CSharpEssentials.Extensions Demo
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 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 (>= 4.0.0)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.0)
-
net6.0
- CSharpEssentials.LoggerHelper (>= 4.0.0)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.0)
-
net8.0
- CSharpEssentials.LoggerHelper (>= 4.0.0)
- Serilog.Sinks.Postgresql.Alternative (>= 3.5.0)
-
net9.0
- CSharpEssentials.LoggerHelper (>= 4.0.0)
- 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 |
|---|---|---|
| 4.1.4 | 0 | 3/30/2026 |
| 4.1.1 | 0 | 3/30/2026 |
| 4.1.0 | 37 | 3/27/2026 |
| 4.0.2 | 306 | 9/13/2025 |
| 4.0.0 | 325 | 8/25/2025 |
| 3.1.5 | 226 | 6/15/2025 |
| 3.1.4 | 353 | 6/12/2025 |
| 3.1.3 | 360 | 6/11/2025 |
| 3.1.2 | 278 | 6/9/2025 |
| 3.1.1 | 260 | 6/8/2025 |
| 3.0.6 | 201 | 6/5/2025 |
| 3.0.5 | 201 | 6/5/2025 |
| 3.0.4 | 203 | 6/2/2025 |
| 3.0.3 | 411 | 6/2/2025 |
| 3.0.2 | 178 | 6/1/2025 |
| 3.0.1 | 162 | 5/30/2025 |
| 1.0.0 | 160 | 5/30/2025 |