S2629 false positive for logging string interpolation if the interpolated in are placeholder names

Please provide

  • Operating system: Windows 10
  • Visual Studio version: VS22
  • SonarLint plugin version:
  • Programming language you’re coding in: C#
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:
This example shows that S2629 is giving a false positive:

using Microsoft.Extensions.Logging;

namespace SonarLintProblems.Models
    public static class PlaceHolderNames
        public const string DeviceId = "DeviceId";
        public const string TemperatureC = "TemperatureC";
        public const string Name = "Name";

    public class NotHappyWithInterpolatingPlaceholderNames
        private readonly ILogger<NotHappyWithInterpolatingPlaceholderNames>? _logger;

        public NotHappyWithInterpolatingPlaceholderNames(ILoggerFactory? loggerFactory)
            _logger = loggerFactory?.CreateLogger<NotHappyWithInterpolatingPlaceholderNames>();

        public void S2629FalsePositive()
            int deviceId = 1;
            double temperatureC = 1.1;
            string name = "whatever";

            // S6676
            _logger?.LogInformation("deviceId:{} name:{} temperatureC:{}", deviceId, name, temperatureC);

            // S2629 and CA2017
            // S2629 is a false positive here because the things inside {} are constants
            _logger?.LogInformation($"deviceId:{PlaceHolderNames.DeviceId} name:{PlaceHolderNames.Name} temperatureC:{PlaceHolderNames.TemperatureC}", deviceId, name, temperatureC);

            // SonarLint is OK with it, but it violates DRY for the named placeholder names
            // because it will be useful in other places to log device id
            // and it is not ideal to hardcode "DeviceId" in potentially many different places
            _logger?.LogInformation("deviceId:{DeviceId} name:{Name} temperatureC:{TemperatureC}", deviceId, name, temperatureC);


Hi, welcome @Chris_P
Thank you for reporting this. I have moved it to the appropriate topic (Report False-positive / False-negative) and tagged the relevant team.


This makes sense. I added it to our backlog: