From 5701a212da8cb4b6b82f473484574b6d128e24a8 Mon Sep 17 00:00:00 2001 From: kurnakovv Date: Sat, 11 Oct 2025 14:43:02 +0900 Subject: [PATCH] Add code example for CA2253 rule (#49089) --- .../code-analysis/quality-rules/ca2253.md | 6 +++++ .../snippets/csharp/all-rules/ca2253.cs | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2253.cs 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); + + // ... + } + } + // +}