Mert Özen Further With Every Line

Blog

Mert Özen's blog posts on software development, backend, frontend, and DevOps.

Series
10 posts found #logging
What to Log and What Not To: A Logging Strategy for .NET and the Anatomy of a Good Log Event
Backend PART 01

What to Log and What Not To: A Logging Strategy for .NET and the Anatomy of a Good Log Event

A good log event is a single occurrence that answers its reader's question: it has a constant message template, meaningful property names and an EventId. We turn five bad log lines in the Bookstore order flow into three events and show level choice, double-logged exceptions and the cost of interpolation caught by CA2254 with real output.

8 Nov 2026 12 min 4
High-Performance Logging: the LoggerMessage Source Generator, IsEnabled and Allocation Cost
Backend PART 02

High-Performance Logging: the LoggerMessage Source Generator, IsEnabled and Allocation Cost

Even a disabled LogDebug line allocates 128 bytes per call because of params object[] and boxing; the [LoggerMessage] source generator brings that to zero with typed parameters and an IsEnabled check. BenchmarkDotNet measurements, an event catalog, primary constructors, [LogProperties] and the cost of the Telemetry package swapping the generator.

8 Nov 2026 12 min 4
Serilog in Depth: Bootstrap Logger, appsettings Configuration, Enrichers and Request Logging
Backend PART 03

Serilog in Depth: Bootstrap Logger, appsettings Configuration, Enrichers and Request Logging

A production-ready Serilog setup has two stages: a bootstrap logger that catches startup failures, then the real logger fed by appsettings and DI. ReadFrom.Configuration, a custom enricher, PushProperty versus BeginScope, UseSerilogRequestLogging writing one summary event per request, and the logs lost when CloseAndFlush is forgotten.

8 Nov 2026 12 min 4
Serilog Sinks: Console, File, Seq and OpenTelemetry — Async, Batching and Lost Logs
Backend PART 04

Serilog Sinks: Console, File, Seq and OpenTelemetry — Async, Batching and Lost Logs

In a container, logs go to stdout as compact JSON; if you need files, set rolling and retention explicitly. Serilog 4's core batching and the async wrapper either drop events or hold the app when a sink is slow: 101 of 2,000 events arrived, or the loop took 2.4 seconds. SelfLog, going out to OTLP and per-sink levels.

8 Nov 2026 11 min 5
Reading Structured Logs with Seq: Docker Setup, Queries, Signals and Alerts
Backend PART 05

Reading Structured Logs with Seq: Docker Setup, Queries, Signals and Alerts

We run Seq in Docker with a password and a separate ingestion port, and send logs through Serilog and OTLP with an Ingest-only API key. Filters, group by and percentile queries, logs and spans on the same TraceId, signals, alerts and signal-based retention, all with real results, including why 8 failures became 16 events and the ERROR level trap with OTLP.

8 Nov 2026 12 min 5
Correlation IDs and Trace Context: Linking Every Log of a Request from the API to the Queue
Backend PART 06

Correlation IDs and Trace Context: Linking Every Log of a Request from the API to the Queue

The way to link every log of a request is to write the TraceId from the W3C traceparent on every log line. ASP.NET Core and HttpClient do it on their own; across a queue and a BackgroundService the chain breaks and must be carried manually with DistributedContextPropagator. ActivityTrackingOptions, Serilog, baggage, X-Correlation-ID, a support code on the error screen and one Seq query, with real output.

8 Nov 2026 10 min 5
Sensitive Data in Logs: Redaction, Data Classification and Privacy-Compliant Logging
Backend PART 07

Sensitive Data in Logs: Redaction, Data Classification and Privacy-Compliant Logging

The way to keep sensitive data out of logs is to classify it and mask it automatically in the logging pipeline. Taxonomy and attributes with Microsoft.Extensions.Compliance.Redaction, [LogProperties], ErasingRedactor, your own redactor and the HMAC redactor that keeps correlation; masking with destructuring in Serilog, personal data in exception messages and a FakeLogger test that catches it, with real output.

8 Nov 2026 11 min 4
HTTP Logging in ASP.NET Core: AddHttpLogging, the W3C Logger and the Cost of Request/Response Bodies
Backend PART 08

HTTP Logging in ASP.NET Core: AddHttpLogging, the W3C Logger and the Cost of Request/Response Bodies

Use HTTP logging in production with one event per request, bodies off, and an interceptor that logs the body only on errors. The real defaults of AddHttpLogging, the header allow list, CombineLogs, [HttpLogging] and WithHttpLogging, an IHttpLoggingInterceptor that logs bodies on 4xx/5xx, the W3C logger file and the measured cost of body logging: 85 KB of allocations per request instead of 8 KB.

8 Nov 2026 9 min 3
Log Levels and Cost: Sampling, Buffering and Changing Log Levels Live in Production
Backend PART 09

Log Levels and Cost: Sampling, Buffering and Changing Log Levels Live in Production

Log volume is set by your level configuration: the same 1000 requests produced 6.3 MB of logs at Debug and 246 KB at Information with Microsoft.AspNetCore=Warning. With real output we show random and trace-based sampling in Microsoft.Extensions.Telemetry, per-request buffering that writes Debug logs on failure, changing levels without a restart, and how sampling can drop Errors and buffers lose scopes and TraceId.

8 Nov 2026 12 min 4
What's New in Logging from .NET 8 to .NET 11: Enrichment, Redaction, FakeLogger, Buffering and Generic LoggerMessage
Backend PART 10

What's New in Logging from .NET 8 to .NET 11: Enrichment, Redaction, FakeLogger, Buffering and Generic LoggerMessage

Logging in .NET moves on two trains: ILogger and the source generator ship with the runtime, while enrichment, redaction, FakeLogger, sampling and buffering come with the monthly Microsoft.Extensions.Telemetry packages. With real output we show which feature arrived when, CA1873 and the obsolete AddServiceLogEnricher in .NET 10, generic LoggerMessage in .NET 11, and how to read old Serilog Startup code.

8 Nov 2026 12 min 4
Blog Map