All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S6677.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Named placeholders in message templates should be unique. The meaning of the named placeholders is to store the value of the provided argument under that name, enabling easier log querying. Since the named placeholder is used multiple times, it cannot store the different values uniquely with each name hence not serving its original purpose. There can be different behaviours when using the same named placeholder multiple times:

The rule covers the following logging frameworks:

How to fix it

Assign unique names to each template placeholder.

Code examples

Noncompliant code example

public void Checkout(ILogger logger, User user, Order order)
{
    logger.LogDebug("User {Id} purchased order {Id}", user.Id, order.Id);
}

Compliant solution

public void Checkout(ILogger logger, User user, Order order)
{
    logger.LogDebug("User {UserId} purchased order {OrderId}", user.Id, order.Id);
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy