Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
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.
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.