File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
docs/fundamentals/code-analysis/quality-rules
snippets/csharp/all-rules Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ helpviewer_keywords:
99- LoggerMessageDefineAnalyzer
1010- CA2253
1111author : Youssef1313
12+ dev_langs :
13+ - CSharp
1214---
1315# CA2253: Named placeholders should not be numeric values
1416
@@ -34,6 +36,10 @@ Rename the numeric placeholder.
3436
3537For usage examples, see the < xref:Microsoft.Extensions.Logging.LoggerExtensions.LogInformation%2A?displayProperty=nameWithType > method.
3638
39+ ## Example
40+
41+ :::code language="csharp" source="snippets/csharp/all-rules/ca2253.cs" id="snippet1":::
42+
3743## When to suppress errors
3844
3945Do not suppress a warning from this rule.
Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Logging ;
2+
3+ namespace ca2253
4+ {
5+ //<snippet1>
6+ public class UserService
7+ {
8+ private readonly ILogger < UserService > _logger ;
9+
10+ public UserService ( ILogger < UserService > logger )
11+ {
12+ _logger = logger ;
13+ }
14+
15+ public void Add ( string firstName , string lastName )
16+ {
17+ // This code violates the rule.
18+ _logger . LogInformation ( "Adding user with first name {0} and last name {1}" , firstName , lastName ) ;
19+
20+ // This code satisfies the rule.
21+ _logger . LogInformation ( "Adding user with first name {FirstName} and last name {LastName}" , firstName , lastName ) ;
22+
23+ // ...
24+ }
25+ }
26+ //</snippet1>
27+ }
You can’t perform that action at this time.
0 commit comments