File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
docs/fundamentals/code-analysis/quality-rules
snippets/csharp/all-rules Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ helpviewer_keywords:
99- CA1727
1010- LoggerMessageDefineAnalyzer
1111author : Youssef1313
12+ dev_langs :
13+ - CSharp
1214---
1315# CA1727: Use PascalCase for named placeholders
1416
@@ -32,6 +34,10 @@ A named placeholder used with <xref:Microsoft.Extensions.Logging.ILogger> should
3234
3335Use PascalCase for named placeholders. For example, change ` {firstName} ` to ` {FirstName} ` .
3436
37+ ## Example
38+
39+ :::code language="csharp" source="snippets/csharp/all-rules/ca1727.cs" id="snippet1":::
40+
3541## When to suppress warnings
3642
3743It is safe to suppress a warning from this rule.
Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Logging ;
2+
3+ namespace ca1727
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 Create ( string firstName , string lastName )
16+ {
17+ // This code violates the rule.
18+ _logger . LogInformation ( "Creating user {firstName} {lastName}" , firstName , lastName ) ;
19+
20+ // This code satisfies the rule.
21+ _logger . LogInformation ( "Creating user {FirstName} {LastName}" , firstName , lastName ) ;
22+ }
23+ }
24+ //</snippet1>
25+ }
You can’t perform that action at this time.
0 commit comments