Skip to content

Use source generated logging everywhere #3908

Description

@marcschier

Microsoft.Extension.Logging ILogger access can be source generated to improve performance. There are several styles that can be used:

  1. static "Log" partial class with static extension methods for ILogger (at end of file or one per area/namespace)
  2. instance log partial class Adapter/Decorator with an ILogger taking constructor and ILogger member.

Preference is option 1. with one static class per existing file (at the end).

There shall be one "internal static class EventIds" class at the root of each project with the public const offsets centrally managed, and each static log class having its log methods start at the offset constant + <number of log message, 0 based>. This allows managing and documenting the event ids via their offsets in a central place. Each offset constant should leave 5 slots for adding additional log messages in the future and then round up to the nearest multiple of 10.

Metadata

Metadata

Assignees

Labels

enhancementAPI or feature enhancement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions