diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2253.md b/docs/fundamentals/code-analysis/quality-rules/ca2253.md index 300148f1e004d..65d4540c7d579 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2253.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2253.md @@ -9,6 +9,8 @@ helpviewer_keywords: - LoggerMessageDefineAnalyzer - CA2253 author: Youssef1313 +dev_langs: +- CSharp --- # CA2253: Named placeholders should not be numeric values @@ -34,6 +36,10 @@ Rename the numeric placeholder. For usage examples, see the method. +## Example + +:::code language="csharp" source="snippets/csharp/all-rules/ca2253.cs" id="snippet1"::: + ## When to suppress errors Do not suppress a warning from this rule. diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2253.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2253.cs new file mode 100644 index 0000000000000..4964dbf5f9c72 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2253.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.Logging; + +namespace ca2253 +{ + // + public class UserService + { + private readonly ILogger _logger; + + public UserService(ILogger logger) + { + _logger = logger; + } + + public void Add(string firstName, string lastName) + { + // This code violates the rule. + _logger.LogInformation("Adding user with first name {0} and last name {1}", firstName, lastName); + + // This code satisfies the rule. + _logger.LogInformation("Adding user with first name {FirstName} and last name {LastName}", firstName, lastName); + + // ... + } + } + // +}