Код: Выделить всё
var productContracts = await context.ProductContracts.ToListAsync();
string contractListSummary = productContracts.ValuesToStringNewLines(c =>
c.GetDescription()
);
// Would like to avoid creating the same message twice
logger.LogInformation(
"All contracts are up to date:\r\n{ContractListSummary}",
contractListSummary
);
await App.Show.AlertSuccess(
$"All contracts are up to date:\r\n{contractListSummary}"
);
< /code>
Методы этого помета, которые регистрируют, показывают оповещения, сообщают о прогрессе и т. Д. С учетом того же кода для создания строки сообщения. < /p>
Есть ли способ избежать этого? < /p>
Например, < /p>
var message = logger.LogInformation(...);
ShowAlert(message);
< /code>
или < /p>
logger.LogInformation(...).Then(message => ShowAlert(message))
< /code>
Можно сделать что -то вроде: < /p>
var message = "My message";
logger.LogInformation("{Message}", message);
ShowAlert(message);
Подробнее здесь: https://stackoverflow.com/questions/794 ... se-message