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
Bendradarbiaukite su mumis dirbdami „GitHub“
Šio turinio šaltinį galima rasti „GitHub“, kur taip pat galite kurti ir peržiūrėti problemas bei teikti užklausas. Daugiau informacijos žr. mūsų bendraautorių vadove.
Atsiliepimai
https://aka.ms/ContentUserFeedback.
Jau greitai: 2024 m. palaipsniui atsisakysime „GitHub“ problemų, kaip turiniui taikomo atsiliepimų mechanizmo, ir pakeisime jį nauja atsiliepimų sistema. Daugiau informacijos žr.Pateikti ir peržiūrėti atsiliepimą, skirtą