Skip to content

Commit a7c4794

Browse files
authored
Use 'LogWarning' method in examples (#44515)
The current method used by examples, `Warning`, does not exist
1 parent 3c4b8ca commit a7c4794

File tree

1 file changed

+4
-4
lines changed
  • docs/fundamentals/code-analysis/quality-rules

1 file changed

+4
-4
lines changed

docs/fundamentals/code-analysis/quality-rules/ca2254.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var lastName = "Otto";
3636

3737
// This tells the logger that there are FirstName and LastName properties
3838
// on the log message, and correlates them with the argument values.
39-
logger.Warning("Person {FirstName} {LastName} encountered an issue", firstName, lastName);
39+
logger.LogWarning("Person {FirstName} {LastName} encountered an issue", firstName, lastName);
4040
```
4141

4242
Not preferred:
@@ -48,10 +48,10 @@ var firstName = "Lorenz";
4848
var lastName = "Otto";
4949

5050
// Here, the log template itself is changing, and the association between named placeholders and their values is lost.
51-
logger.Warning("Person " + firstName + " " + lastName + " encountered an issue");
51+
logger.LogWarning("Person " + firstName + " " + lastName + " encountered an issue");
5252

5353
// String interpolation also loses the association between placeholder names and their values.
54-
logger.Warning($"Person {firstName} {lastName} encountered an issue");
54+
logger.LogWarning($"Person {firstName} {lastName} encountered an issue");
5555
```
5656

5757
The logging message template should not vary between calls.
@@ -61,7 +61,7 @@ The logging message template should not vary between calls.
6161
Update the message template to be a constant expression. If you're using values directly in the template, refactor the template to use named placeholders instead.
6262

6363
```csharp
64-
logger.Warning("Person {FirstName} {LastName} encountered an issue", firstName, lastName);
64+
logger.LogWarning("Person {FirstName} {LastName} encountered an issue", firstName, lastName);
6565
```
6666

6767
For usage examples, see the <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogInformation%2A?displayProperty=nameWithType> method.

0 commit comments

Comments
 (0)