Skip to content
Open
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
4 changes: 2 additions & 2 deletions docs/fundamentals/code-analysis/quality-rules/ca1873.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ In many situations, logging is disabled or set to a log level that results in an

## Rule description

When logging methods are called, their arguments are evaluated regardless of whether the logging level is enabled. This can result in expensive operations being executed even when the log message won't be written. For better performance, guard expensive logging calls with a check to <xref:Microsoft.Extensions.Logging.ILogger.IsEnabled%2A> or use the `LoggerMessage` pattern.
When logging methods are called, their arguments are evaluated regardless of whether the logging level is enabled. This can result in expensive operations being executed even when the log message won't be written. For better performance, guard expensive logging calls with a check to <xref:Microsoft.Extensions.Logging.ILogger.IsEnabled%2A> or use **source-generated logging** with the <xref:Microsoft.Extensions.Logging.LoggerMessageAttribute> attribute.

## How to fix violations

To fix a violation of this rule, use one of the following approaches:

- Guard the logging call with a check to <xref:Microsoft.Extensions.Logging.ILogger.IsEnabled%2A>.
- Use the `LoggerMessage` pattern with <xref:Microsoft.Extensions.Logging.LoggerMessageAttribute>.
- Use **source-generated logging** with the <xref:Microsoft.Extensions.Logging.LoggerMessageAttribute> attribute for better performance and compile-time safety.
- Ensure expensive operations aren't performed in logging arguments unless necessary.

## Example
Expand Down