Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1727.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ helpviewer_keywords:
- CA1727
- LoggerMessageDefineAnalyzer
author: Youssef1313
dev_langs:
- CSharp
---
# CA1727: Use PascalCase for named placeholders

Expand All @@ -32,6 +34,10 @@ A named placeholder used with <xref:Microsoft.Extensions.Logging.ILogger> should

Use PascalCase for named placeholders. For example, change `{firstName}` to `{FirstName}`.

## Example

:::code language="csharp" source="snippets/csharp/all-rules/ca1727.cs" id="snippet1":::

## When to suppress warnings

It is safe to suppress a warning from this rule.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Extensions.Logging;

namespace ca1727
{
//<snippet1>
public class UserService
{
private readonly ILogger<UserService> _logger;

public UserService(ILogger<UserService> logger)
{
_logger = logger;
}

public void Create(string firstName, string lastName)
{
// This code violates the rule.
_logger.LogInformation("Creating user {firstName} {lastName}", firstName, lastName);

// This code satisfies the rule.
_logger.LogInformation("Creating user {FirstName} {LastName}", firstName, lastName);
}
}
//</snippet1>
}
Loading