Код: Выделить всё
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" );
В основном, независимо от того, что я делаю, logger.loginformation содержит расчеты . Я пробовал: < /p>
Код: Выделить всё
using var _ = LogContext.PushProperty( .. );Код: Выделить всё
using ( var _ = LogCOntext.PushProperty( .. ) ) { .. }- I've moved entire lambda body to separate function and simply assigned parameter as body: RunCalculation.
является тем, что ожидаемое поведение pushproperty ? >
Подробнее здесь: https://stackoverflow.com/questions/794 ... properties