Here is a discussion of other people experiencing similar issues regarding CA2254. Hopefull this will get addressed in future versions.
For the time being, my best solution is to ignore the warning.
private async Task LogWarningToDatabaseAsync(short? userCodeId, string message, params object[] args)
{
#pragma warning disable CA2254 // Template should be a static expression
_logger.LogWarning(message, args);
#pragma warning restore CA2254 // Template should be a static expression
// Do something on the database...
}
The alternative is not very exciting.
private async Task LogWarningToDatabaseAsync(short? userCodeId, string message, params object[] args)
{
// Move to parent.
//_logger.LogWarning(message, args);
// Do something on the database...
}
private async Task SampleAsync(short? userCodeId, string aaa, string bbb)
{
// I'm not happy about repeating the input message every time this gets called.
_logger.LogWarning("My sample message with data {aaa} and more data {bbb}", aaa, bbb);
await LogWarningToDatabaseAsync(userCodeId, "My sample message with data {aaa} and more data {bbb}", aaa, bbb);
}