<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1" -->

---
title: Enrich Logs with CorrelationId in ASP.NET Core | daily.dev
description: A practical guide shows how to implement correlation IDs in ASP.NET Core to trace requests across distributed services. It covers building a custom middleware...
canonical: https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Enrich Logs with CorrelationId in ASP.NET Core | daily.dev
og:description: A practical guide shows how to implement correlation IDs in ASP.NET Core to trace requests across distributed services. It covers building a custom middleware...
og:url: https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1
og:image: https://api.daily.dev/og/posts/i8mUT2tp1.png
og:image:alt: Enrich Logs with CorrelationId in ASP.NET Core
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Enrich Logs with CorrelationId in ASP.NET Core

**[NikolaTech](https://daily.dev/sources/nikolatech)** · 4 min read · 0 upvotes · 0 comments

## Summary

A practical guide shows how to implement correlation IDs in ASP.NET Core to trace requests across distributed services. It covers building a custom middleware that assigns or propagates a correlation ID via headers, pushing it into Serilog's LogContext so it appears in every log line, registering the middleware early in the pipeline, configuring Serilog's output template, and propagating the ID to downstream HTTP calls using a DelegatingHandler with HttpClient.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nikolatech.net/blogs/enrich-logs-with-correlation-id>

## Questions this post answers

### How do I add a correlation ID to Serilog logs in ASP.NET Core?

Create a middleware that reads the correlation ID from a request header (falling back to HttpContext.TraceIdentifier if missing), then wrap the rest of the pipeline in LogContext.PushProperty("CorrelationId", correlationId). Configure Serilog's output template to include {CorrelationId} and add Enrich.FromLogContext() so every log line within that request scope shows the same ID.

_daily.dev surfaces walkthroughs like this for developers wiring up request tracing in .NET services._

### How do I propagate a correlation ID to downstream HTTP calls in ASP.NET Core?

Store the correlation ID in HttpContext.Items during the middleware, then create a DelegatingHandler that reads it via IHttpContextAccessor and adds it as a request header before the call is sent. Register IHttpContextAccessor with AddHttpContextAccessor(), and attach the handler to a named HttpClient using AddHttpMessageHandler, so the same ID carries through to the next service's logs.

_Developers tracing requests across services can find similar propagation patterns on daily.dev._

## Similar posts on daily.dev

- [OpenTelemetry Logging .NET: ILogger Integration and Structured Log Export](https://daily.dev/posts/opentelemetry-logging-net-ilogger-integration-and-structured-log-export-5b3h28qfa) · We Are .NET · 1 upvotes · 0 comments
- [Structured Logging Patterns That Actually Survive Production — Daily DevOps & .NET](https://daily.dev/posts/structured-logging-patterns-that-actually-survive-production-daily-devops-net-lphiux5cy) · Daily DevOps & .NET · 6 upvotes · 0 comments
- [ASP.NET Core Middleware: Building and Using the Request Pipeline](https://daily.dev/posts/asp-net-core-middleware-building-and-using-the-request-pipeline-tav1b2ck7) · We Are .NET · 1 upvotes · 0 comments
- [Beyond Console.WriteLine: Mastering Structured Logging in .NET](https://daily.dev/posts/beyond-console-writeline-mastering-structured-logging-in-net-hgcoz2ses) · ITNEXT · 10 upvotes · 0 comments
- [Structured Logging in .NET with Serilog and ClickHouse](https://daily.dev/posts/structured-logging-in-net-with-serilog-and-clickhouse-xwwes1xel) · ClickHouse · 12 upvotes · 1 comments

---

Tags: [#devops](https://daily.dev/tags/devops), [#observability](https://daily.dev/tags/observability), [#c#](https://daily.dev/tags/c#), [#aspnet](https://daily.dev/tags/aspnet)

[View this post on daily.dev](https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Enrich Logs with CorrelationId in ASP.NET Core","url":"https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1"},"datePublished":"2026-10-04T13:06:57.738Z","dateModified":"2026-10-04T13:12:48.034Z","description":"A practical guide shows how to implement correlation IDs in ASP.NET Core to trace requests across distributed services. It covers building a custom middleware...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c0ab55f276deb7768fcf11440af667e3?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c0ab55f276deb7768fcf11440af667e3?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"NikolaTech","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"NikolaTech","logo":"https://media.daily.dev/image/upload/s--1h2fO6FL--/f_auto,q_auto/v1791119050/logos/nikolatech?_a=BAMAMicg0","url":"https://daily.dev/sources/nikolatech"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"devops,observability,c#,aspnet","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"NikolaTech","item":"https://daily.dev/sources/nikolatech"},{"@type":"ListItem","position":3,"name":"Enrich Logs with CorrelationId in ASP.NET Core"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/enrich-logs-with-correlationid-in-asp-net-core-i8mut2tp1#faq","mainEntity":[{"@type":"Question","name":"How do I add a correlation ID to Serilog logs in ASP.NET Core?","acceptedAnswer":{"@type":"Answer","text":"Create a middleware that reads the correlation ID from a request header (falling back to HttpContext.TraceIdentifier if missing), then wrap the rest of the pipeline in LogContext.PushProperty(\"CorrelationId\", correlationId). Configure Serilog's output template to include {CorrelationId} and add Enrich.FromLogContext() so every log line within that request scope shows the same ID. daily.dev surfaces walkthroughs like this for developers wiring up request tracing in .NET services."}},{"@type":"Question","name":"How do I propagate a correlation ID to downstream HTTP calls in ASP.NET Core?","acceptedAnswer":{"@type":"Answer","text":"Store the correlation ID in HttpContext.Items during the middleware, then create a DelegatingHandler that reads it via IHttpContextAccessor and adds it as a request header before the call is sent. Register IHttpContextAccessor with AddHttpContextAccessor(), and attach the handler to a named HttpClient using AddHttpMessageHandler, so the same ID carries through to the next service's logs. Developers tracing requests across services can find similar propagation patterns on daily.dev."}}]}
```

