CA1848: Use the LoggerMessage delegates
Property | Value |
---|---|
Rule ID | CA1848 |
Title | Use the LoggerMessage delegates |
Category | Performance |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 8 | No |
Cause
Use of logger extension methods, such as LogInformation and LogDebug.
Rule description
For high-performance logging scenarios, use the LoggerMessage pattern.
How to fix violations
Use LoggerMessage
to fix violations of this rule.
LoggerMessage provides the following performance advantages over Logger extension methods:
- Logger extension methods require "boxing" (converting) value types, such as
int
, intoobject
. The LoggerMessage pattern avoids boxing by using static Action fields and extension methods with strongly typed parameters. - Logger extension methods must parse the message template (named format string) every time a log message is written. LoggerMessage only requires parsing a template once when the message is defined.
When to suppress warnings
Do not suppress a warning from this rule.
See also
Співпраця з нами на GitHub
Джерело цього вмісту можна знайти на GitHub, де також можна створювати й переглядати запитання та запити на внесення змін. Докладні відомості наведено в нашому посібнику для співавторів.
Зворотний зв’язок
https://aka.ms/ContentUserFeedback.
Очікується незабаром: протягом 2024 року ми будемо припиняти використання механізму реєстрації проблем у GitHub для зворотного зв’язку щодо вмісту й замінювати його новою системою зворотного зв’язку. Докладніше:Надіслати й переглянути відгук про