Purview.Telemetry.SourceGenerator
2.0.1
dotnet add package Purview.Telemetry.SourceGenerator --version 2.0.1
NuGet\Install-Package Purview.Telemetry.SourceGenerator -Version 2.0.1
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Purview.Telemetry.SourceGenerator --version 2.0.1
#r "nuget: Purview.Telemetry.SourceGenerator, 2.0.1"
// Install Purview.Telemetry.SourceGenerator as a Cake Addin #addin nuget:?package=Purview.Telemetry.SourceGenerator&version=2.0.1 // Install Purview.Telemetry.SourceGenerator as a Cake Tool #tool nuget:?package=Purview.Telemetry.SourceGenerator&version=2.0.1
Purview Telemetry Source Generator
Generates ActivitySource, High-performance logging and Metrics based on methods on an interface, enabling fast iteration cycles, dependency injection and substitutes for testing.
The latest version is available on NuGet, and supports generation for the following frameworks:
- .NET Framework 4.7.2
- .NET Framework 4.8
- .NET 8
- .NET 9
Reference in your Directory.Build.props
or .csproj
file:
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Example of a multi-target telemetry interface:
using Purview.Telemetry.Activities;
using Purview.Telemetry.Logging;
using Purview.Telemetry.Metrics;
[ActivitySource]
[Logger]
[Meter]
interface IEntityStoreTelemetry
{
/// <summary>
/// Creates and starts an Activity and adds the parameters as Tags and Baggage.
/// </summary>
[Activity]
Activity? GettingEntityFromStore(int entityId, [Baggage]string serviceUrl);
/// <summary>
/// Adds an ActivityEvent to the Activity with the parameters as Tags.
/// </summary>
[Event]
void GetDuration(Activity? activity, int durationInMS);
/// <summary>
/// Adds the parameters as Baggage to the Activity.
/// </summary>
[Context]
void RetrievedEntity(Activity? activity, float totalValue, int lastUpdatedByUserId);
/// <summary>
/// Generates a structured log message using an ILogger - defaults to Informational.
/// </summary>
[Log]
void ProcessingEntity(int entityId, string updateState);
/// <summary>
/// Generates a structured log message using an ILogger, specifically defined as Informational.
/// </summary>
[Info]
void ProcessingAnotherEntity(int entityId, string updateState);
/// <summary>
/// Adds 1 to a Counter<T> with the entityId as a Tag.
/// </summary>
[AutoCounter]
void RetrievingEntity(int entityId);
}
For more information see the wiki.
To see the generated output for the above, see the
Generated Output
page in the wiki.
Example Project
Checkout the .NET Aspire Sample Project to see the Activities, Logging, and Metrics working with the Aspire Dashboard.
This sample project has
EmitCompilerGeneratedFiles
set totrue
, so you can easily see the generated output.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.1 | 71 | 2/2/2025 |
2.0.0 | 63 | 2/1/2025 |
1.1.0 | 103 | 12/8/2024 |
1.0.12 | 137 | 6/9/2024 |
1.0.11 | 146 | 6/3/2024 |
1.0.10 | 110 | 6/3/2024 |
1.0.9 | 126 | 5/30/2024 |
1.0.8 | 115 | 5/27/2024 |
1.0.7 | 121 | 5/20/2024 |
1.0.6 | 127 | 5/20/2024 |
1.0.5 | 138 | 5/6/2024 |
1.0.4 | 108 | 5/1/2024 |
1.0.3 | 340 | 4/30/2024 |
1.0.2 | 122 | 4/25/2024 |
1.0.1 | 115 | 4/25/2024 |
1.0.0 | 122 | 4/22/2024 |
0.0.14-prerelease | 112 | 4/8/2024 |
0.0.13-prerelease | 112 | 4/7/2024 |
0.0.12-prerelease | 102 | 4/6/2024 |
0.0.11-prerelease | 108 | 4/6/2024 |
0.0.10-prerelease | 103 | 4/6/2024 |