Hi,
we are using the SonarQube Server Developer Edition (v2025.2) with C#.
The rule S2629 seems to be correct für the Microsoft logging framework but I think it is misleading using log4net (3.0.0).
log4net can’t handle string pattern like the Microsoft logging framework does using named placeholders. Just index based placeholders for the string.Format method.
Using string interpolation with log4net causes an error by the rule S2629.
logger.Debug($“The value of the parameter is: {parameter}.”);
and the rule suggests to use this
logger.DebugFormat(“The value of the parameter is: {Parameter}.”, parameter);
But log4net does not support this. DebugFormat just uses string.Format internally and the correct using should be
logger.DebugFormat(“The value of the parameter is: {0}.”, parameter);
Additionally I think using the “normal” method Debug instead of DebugFormat with string interpolation should be also fine as the alternative (using string.Format internally) is not better as string interpolation.
So this should be fine with log4net:
logger.Debug($“The value of the parameter is: {parameter}.”);
We hit this case many times in our code and don’t want to disable the rule because we also use it for Microsoft logging where the rule is really helpful.
Correct me if I am wrong, but in my eyes the rule is misleading when working with log4net.