---
title: "Structured Logging in .NET with Serilog and ClickHouse"
description: "Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call."
url: "https://swe.quest/articles/structured-logging-in-net-with-serilog-and-clickhouse-433c37101ab76f06"
canonical: "https://clickhouse.com/blog/serilog"
source: "ClickHouse"
published: "2026-03-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 20
tags: ["dotnet","observability","analytics"]
---

# Structured Logging in .NET with Serilog and ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-03-23, 20 min read, How-to. Original: [https://clickhouse.com/blog/serilog](https://clickhouse.com/blog/serilog)

## Summary

Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call. A fluent C# schema builder controls the table: typed JSON property hints, promoted columns such as CorrelationId, a text inverted index on messages, a MergeTree ORDER BY key and a TTL. The demo also covers correlation ID middleware via LogContext, single per-request summary events with UseSerilogRequestLogging and IDiagnosticContext, and flushing batched events with Log.CloseAndFlushAsync on shutdown. For production, manage the schema externally rather than letting the sink create it, and tune compression codecs and Kubernetes-aware sort keys.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [.NET](https://swe.quest/tags/dotnet.md) (Languages)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)

## Prerequisites

- ASP.NET Core middleware
- Serilog basics
- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

Serilog, ClickHouse, ASP.NET Core, ClickStack, MergeTree, Docker Compose

## Related posts

- [ClickHouse and OpenTelemetry](https://swe.quest/articles/clickhouse-and-opentelemetry-84cdeb7807e844a6.md): ClickHouse · 2024-11-07 · Medium · 10 min read · Observability, Analytics & OLAP, Databases, Open source
  ClickHouse now officially supports the OpenTelemetry Collector exporter for ClickHouse, which has reached beta for logs and traces.
- [Building a .NET API Gateway with ClickHouse and Aspire](https://swe.quest/articles/building-a-net-api-gateway-with-clickhouse-and-aspire-d43f7774c1e69e19.md): ClickHouse · 2026-06-02 · Medium · 13 min read · .NET, Analytics & OLAP, Observability, Load balancing
  A sample .NET API gateway uses Aspire to orchestrate a ClickHouse container, a YARP gateway, backend APIs, a load generator, an analytics API and a Blazor dashboard.
- [Sending Windows Event Logs to ClickHouse with Fluent Bit](https://swe.quest/articles/sending-windows-event-logs-to-clickhouse-with-fluent-bit-a9cd29ea6f2c615f.md): ClickHouse · 2023-01-17 · Medium · 10 min read · Observability, Analytics & OLAP, Threat detection
  Fluent Bit's winevtlog input can collect Windows Event Logs, including the Sysmon/Operational and Security channels, and ship them to ClickHouse over HTTP as JSONEachRow with async\_insert enabled.
- [How trip.com migrated from Elasticsearch and built a 50PB logging solution with ClickHouse](https://swe.quest/articles/how-trip-com-migrated-from-elasticsearch-and-built-a-50pb-logging-solution-with-079ade1f405efcf8.md): ClickHouse · 2024-06-12 · Medium · 16 min read · Analytics & OLAP, Observability, Scaling, Cost optimization, Databases
  Trip.com replaced its Elasticsearch-based centralized logging platform with ClickHouse after hitting stability, ingestion and cost limits at 4PB, and has since grown it toward 50PB.
- [Clever ingests 200x more logs at the same cost with ClickHouse Cloud](https://swe.quest/articles/clever-ingests-200x-more-logs-at-the-same-cost-with-clickhouse-cloud-cafdd48afca59e57.md): ClickHouse · 2026-06-30 · Medium · 8 min read · Observability, Analytics & OLAP, Cost optimization, System design
  Clever replaced a split Datadog/Athena logging setup with ClickHouse Cloud.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
