NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi
1.0.1
dotnet add package NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi --version 1.0.1
NuGet\Install-Package NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi" Version="1.0.1" />
<PackageReference Include="NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi&version=1.0.1
#tool nuget:?package=NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Core.CrossCuttingConcerns.CorrelationId.WebApi
ASP.NET Core middleware and extensions: reads the incoming X-Correlation-Id header, falls back to the active distributed trace ID if absent, and generates a new GUID if neither is available. It propagates the value as a response header and automatically enriches the Serilog LogContext.
Installation
dotnet add package NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId.WebApi
Program.cs
// 1. DI registration
builder.Services.AddCorrelationId();
// 2. Middleware — add at the start of the pipeline, before the exception middleware
app.UseCorrelationId();
app.ConfigureCustomExceptionMiddleware(); // exception logs also carry the CorrelationId
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
appsettings.json — Serilog template
For {CorrelationId} to appear in log lines, users of Core.CrossCuttingConcerns.Logging.Serilog.File should add it to the template:
{
"FileLogConfiguration": {
"FolderPath": "Logs",
"MinLogLevel": "Information",
"LogOutputTemplate": "[{Timestamp:dd.MM.yyyy HH:mm:ss}] [{Level:u3}] [{CorrelationId}] {Message:lj}{NewLine}{Exception}",
"SpecificLogFolders": []
}
}
Access Points
| Location | How |
|---|---|
| Controller / Service (DI) | ICorrelationIdAccessor.CorrelationId |
| HttpContext | httpContext.GetCorrelationId() |
| Response header | X-Correlation-Id |
| Serilog log lines | Automatic — {CorrelationId} template property |
ID Priority Order
- Incoming
X-Correlation-Idrequest header (API gateway / service mesh propagation) Activity.Current?.TraceId— aligns with the trace when OpenTelemetry or Application Insights is activeGuid.NewGuid()— standalone fallback
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- NetCoreBackend.NArchitecture.Core.CrossCuttingConcerns.CorrelationId (>= 1.0.1)
- Serilog (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.