-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from purview-dev/add-diagnostics-and-log-attribs
Add diagnostics and log attribs
- Loading branch information
Showing
1,546 changed files
with
117,087 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...tor.IntegrationTests/Logging/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
namespace Purview.Telemetry.SourceGenerator.Logging; | ||
|
||
partial class TelemetrySourceGeneratorLoggingTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(SpecificLogAttributeTypes))] | ||
public async Task Generate_GivenInterfaceWithSpecificLogAttribute_GenerateLoggerWithThatLevel(string attribute) | ||
{ | ||
// Arrange | ||
string basicLogger = @$" | ||
using Purview.Telemetry.Logging; | ||
namespace Testing; | ||
[Logger] | ||
public interface ITestLogger | ||
{{ | ||
[{attribute}] | ||
void Log(string stringParam, int intParam, bool boolParam); | ||
}} | ||
"; | ||
|
||
// Act | ||
var generationResult = await GenerateAsync(basicLogger); | ||
|
||
// Assert | ||
await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(attribute)); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SpecificLogAttributeTypes))] | ||
public async Task Generate_GivenInterfaceWithSpecificTypesAndSpecificParameters_GenerateLoggerWithThatLevelAndParameter(string attribute) | ||
{ | ||
// Arrange | ||
string basicLogger = @$" | ||
using Purview.Telemetry.Logging; | ||
namespace Testing; | ||
[Logger] | ||
public interface ITestLogger | ||
{{ | ||
[{attribute}] | ||
void Log(string stringParam, int intParam, bool boolParam); | ||
[{attribute}(eventId: 100)] | ||
void Log_EventId_1(string stringParam, int intParam, bool boolParam); | ||
[{attribute}(100)] | ||
void Log_EventId_3(string stringParam, int intParam, bool boolParam); | ||
[{attribute}(messageTemplate: ""template"")] | ||
void Log_MessageTemplate_1(string stringParam, int intParam, bool boolParam); | ||
[{attribute}(MessageTemplate = ""template"")] | ||
void Log_MessageTemplate_2(string stringParam, int intParam, bool boolParam); | ||
[{attribute}(""template"")] | ||
void Log_MessageTemplate_3(string stringParam, int intParam, bool boolParam); | ||
}} | ||
"; | ||
|
||
// Act | ||
var generationResult = await GenerateAsync(basicLogger); | ||
|
||
// Assert | ||
await TestHelpers.Verify(generationResult, c => c.UseHashedParameters(attribute)); | ||
} | ||
|
||
public static TheoryData<string> SpecificLogAttributeTypes | ||
{ | ||
get | ||
{ | ||
TheoryData<string> data = []; | ||
|
||
data.Add("Trace"); | ||
data.Add("Debug"); | ||
data.Add("Info"); | ||
data.Add("Warning"); | ||
data.Add("Error"); | ||
data.Add("Critical"); | ||
|
||
return data; | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...enerate_GivenAssemblyEnableDI_GeneratesActivity.DotNet8_0#CriticalAttribute.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//HintName: CriticalAttribute.g.cs | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by the Purview.Telemetry.SourceGenerator | ||
// on {Scrubbed}. | ||
// | ||
// Changes to this file may cause incorrect behaviour and will be lost | ||
// when the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#pragma warning disable 1591 // publicly visible type or member must be documented | ||
|
||
#nullable enable | ||
|
||
namespace Purview.Telemetry.Logging; | ||
|
||
/// <summary> | ||
/// Marker attribute used as an alternative to <see cref="LogAttribute"/>, where the <see cref="LogAttribute.Level"/> | ||
/// is set to <see cref="Microsoft.Extensions.Logging.LogLevel.Critical"/>. | ||
/// </summary> | ||
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] | ||
[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] | ||
sealed class CriticalAttribute : System.Attribute | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="CriticalAttribute"/>, specifying the <see cref="MessageTemplate"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Specifies the <see cref="MessageTemplate"/>.</param> | ||
public CriticalAttribute(string messageTemplate) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="CriticalAttribute"/>, specifying the <see cref="EventId"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
public CriticalAttribute(int eventId) | ||
{ | ||
EventId = eventId; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="CriticalAttribute"/>, | ||
/// optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public CriticalAttribute(string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="CriticalAttribute"/>, specifying the <see cref="EventId"/> | ||
/// and the <see cref="Level"/>, optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public CriticalAttribute(int eventId, string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
EventId = eventId; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Optional. The message template used for the log entry, otherwise one is | ||
/// generated based on the parameters. | ||
/// </summary> | ||
public string? MessageTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. | ||
/// </summary> | ||
public int? EventId { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. | ||
/// </summary> | ||
public string? Name { get; set; } | ||
} |
86 changes: 86 additions & 0 deletions
86
...s.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet8_0#DebugAttribute.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//HintName: DebugAttribute.g.cs | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by the Purview.Telemetry.SourceGenerator | ||
// on {Scrubbed}. | ||
// | ||
// Changes to this file may cause incorrect behaviour and will be lost | ||
// when the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#pragma warning disable 1591 // publicly visible type or member must be documented | ||
|
||
#nullable enable | ||
|
||
namespace Purview.Telemetry.Logging; | ||
|
||
/// <summary> | ||
/// Marker attribute used as an alternative to <see cref="LogAttribute"/>, where the <see cref="LogAttribute.Level"/> | ||
/// is set to <see cref="Microsoft.Extensions.Logging.LogLevel.Debug"/>. | ||
/// </summary> | ||
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] | ||
[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] | ||
sealed class DebugAttribute : System.Attribute | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="DebugAttribute"/>, specifying the <see cref="MessageTemplate"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Specifies the <see cref="MessageTemplate"/>.</param> | ||
public DebugAttribute(string messageTemplate) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="DebugAttribute"/>, specifying the <see cref="EventId"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
public DebugAttribute(int eventId) | ||
{ | ||
EventId = eventId; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="DebugAttribute"/>, | ||
/// optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public DebugAttribute(string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="DebugAttribute"/>, specifying the <see cref="EventId"/> | ||
/// and the <see cref="Level"/>, optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public DebugAttribute(int eventId, string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
EventId = eventId; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Optional. The message template used for the log entry, otherwise one is | ||
/// generated based on the parameters. | ||
/// </summary> | ||
public string? MessageTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. | ||
/// </summary> | ||
public int? EventId { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. | ||
/// </summary> | ||
public string? Name { get; set; } | ||
} |
86 changes: 86 additions & 0 deletions
86
...s.Generate_GivenAssemblyEnableDI_GeneratesActivity.DotNet8_0#ErrorAttribute.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//HintName: ErrorAttribute.g.cs | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by the Purview.Telemetry.SourceGenerator | ||
// on {Scrubbed}. | ||
// | ||
// Changes to this file may cause incorrect behaviour and will be lost | ||
// when the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#pragma warning disable 1591 // publicly visible type or member must be documented | ||
|
||
#nullable enable | ||
|
||
namespace Purview.Telemetry.Logging; | ||
|
||
/// <summary> | ||
/// Marker attribute used as an alternative to <see cref="LogAttribute"/>, where the <see cref="LogAttribute.Level"/> | ||
/// is set to <see cref="Microsoft.Extensions.Logging.LogLevel.Error"/>. | ||
/// </summary> | ||
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] | ||
[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] | ||
sealed class ErrorAttribute : System.Attribute | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="ErrorAttribute"/>, specifying the <see cref="MessageTemplate"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Specifies the <see cref="MessageTemplate"/>.</param> | ||
public ErrorAttribute(string messageTemplate) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="ErrorAttribute"/>, specifying the <see cref="EventId"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
public ErrorAttribute(int eventId) | ||
{ | ||
EventId = eventId; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="ErrorAttribute"/>, | ||
/// optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public ErrorAttribute(string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of the <see cref="ErrorAttribute"/>, specifying the <see cref="EventId"/> | ||
/// and the <see cref="Level"/>, optionally the <see cref="MessageTemplate"/> and <see cref="Name"/>. | ||
/// </summary> | ||
/// <param name="eventId">Specifies the <see cref="EventId"/>.</param> | ||
/// <param name="messageTemplate">Optionally specifies the <see cref="MessageTemplate"/>.</param> | ||
/// <param name="name">Optionally specifies the <see cref="Name"/>.</param> | ||
public ErrorAttribute(int eventId, string? messageTemplate = null, string? name = null) | ||
{ | ||
MessageTemplate = messageTemplate; | ||
EventId = eventId; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Optional. The message template used for the log entry, otherwise one is | ||
/// generated based on the parameters. | ||
/// </summary> | ||
public string? MessageTemplate { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. | ||
/// </summary> | ||
public int? EventId { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. | ||
/// </summary> | ||
public string? Name { get; set; } | ||
} |
Oops, something went wrong.