-
Notifications
You must be signed in to change notification settings - Fork 3
Logging
There are two distinct generated types for ILogger-based generation.
This is the default generation method when the Microsoft.Extensions.Telemetry.Abstractions package is referenced either directly or in-directly.
The generated log implementations more closely resembles the output from the Microsoft.Gen.Logging generator, but with a few additional features.
These include the ability to generate a MessageTemplate dynamically, and enumerate a capture elements in an array/ IEnumerable.
You can control the generation mode via the GenerationMode property on [LoggerAttribute] (per-interface) or [LoggerGenerationAttribute] (assembly-level). Set LoggerGenerationMode.V1 to force v1 generation, or LoggerGenerationMode.V2 to force v2. The default Auto selects the best mode per method based on parameters.
More details can be found in the Generation v2 page.
This is the default generation method when the Microsoft.Extensions.Telemetry.Abstractions package is not referenced, or when GenerationMode is set to LoggerGenerationMode.V1 on [LoggerAttribute] or [LoggerGenerationAttribute].
This type of generation utilises the older-style High-performance logging.
More details can be found in the Generation v1 page.
To disable logger-based generation in your project add a build constant to either you .csproj or Directory.Build.props with a value of EXCLUDE_PURVIEW_TELEMETRY_LOGGING, and the logging attributes will be ignored.
<!-- In a .csproj -->
<DefineConstants>EXCLUDE_PURVIEW_TELEMETRY_LOGGING</DefineConstants>
<!-- In a Directory.Build.Props -->
<PropertyGroup>
<DefineConstants>EXCLUDE_PURVIEW_TELEMETRY_LOGGING</DefineConstants>
</PropertyGroup>This primarily used for when the Microsoft.Extensions.Logging.ILogger type is unavailable. In this case your project will fail to compile due to the generated attributes using related types such as the LogLevel.
Important
Consider helping children around the world affected by conflict. You can donate any amount to War Child here - any amount can help save a life.
Purview Telemetry Source Generator v4.0.0-prerelease.1 | Home | Getting Started | FAQ | Breaking Changes | GitHub