Serilog logcontext.pushProperty nicht auslösen, um Eigenschaften zu entfernen
Posted: 01 Mar 2025, 11:53
Ich habe den folgenden Code: < /p>
my foreachaSync () ist die Implementierung aus diesem Beitrag. Ich habe es versucht: < /p>
Code: Select all
var calculationsTask = request.CalcEngines.ForEachAsync(
new ParallelOptions
{
MaxDegreeOfParallelism = int.MaxValue,
CancellationToken = cancellationToken
},
async ( item, ct ) =>
{
var calculationId = Guid.NewGuid();
var calculationStopwatch = Stopwatch.StartNew();
LogContext.PushProperty( "calculationId", calculationId );
await Task.Delay( 1, ct ); // simulate async work
}
);
var calculationResponses = await calculationsTask;
logger.LogInformation( "Test log" );
Code: Select all
using var _ = LogContext.PushProperty( .. );
Code: Select all
using ( var _ = LogCOntext.PushProperty( .. ) ) { .. }
- I've moved entire lambda body to separate function and simply assigned parameter as body: RunCalculation.