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
Cộng tác với chúng tôi trên GitHub
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho