This package allows arbitrary data to be stored in the context of async operations.
$ dotnet add package OperationContext.CoreThis package allows arbitrary data to be stored in the context of async operations.
Install NuGet package
dotnet add package OperationContext.AspNetCore
Open the Program.cs file and configure OperationContext.
Register OperationContext in DI container
builder.Services.Configure<OperationContextOptions>(opt =>
opt.CorrelationIdHttpHeaderName = "X-Correlation-ID"
);
builder.Services.AddOperationContext();
Add required ASP.NET Core middlewares
app.UseOperationContext(cfg =>
{
cfg.CreateLoggerScope = true;
cfg.AddCorrelationId = true;
});
Or
app.UseOperationContext();
app.UseOperationContextLogger();
app.UseCorrelationId();
Install NuGet package
dotnet add package OperationContext.Hangfire
Open the Program.cs file and configure OperationContext.
Register OperationContext in DI container
builder.Services.AddOperationContext();
Add required Hangfire filters
services.AddHangfire((provider, cfg) =>
cfg. ...
.UseOperationContext(
provider,
x =>
{
x.CreateLoggerScope = true;
x.AddCorrelationId = true;
}
)
);
Or
services.AddHangfire((provider, cfg) =>
cfg. ...
.UseOperationContext(provider)
.UseOperationContextLogger(provider)
.UseCorrelationId(provider)
);