Skip to content

Commit 3194512

Browse files
authored
Remove experimental attribute from TagNameAttribute (#6200)
* remove experimental from TagNameAttribute
1 parent 035623e commit 3194512

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Logging/TagNameAttribute.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@
33

44
using System;
55
using System.Diagnostics;
6-
using System.Diagnostics.CodeAnalysis;
7-
using Microsoft.Shared.DiagnosticIds;
86
using Microsoft.Shared.Diagnostics;
97

108
namespace Microsoft.Extensions.Logging;
119

1210
/// <summary>
1311
/// Defines the tag name to use for a logged parameter or property.
1412
/// </summary>
13+
/// <remarks>
14+
/// By default, the tag name is the same as the respective parameter or property.
15+
/// You can use this attribute to override the default and provide a custom tag name.
16+
/// </remarks>
17+
/// <example>
18+
/// <code language="csharp">
19+
/// [LoggerMessage(1, LogLevel.Information, "My custom tag name: {my.custom.tagname}")]
20+
/// public static partial void LogMyCustomTagName(
21+
/// this ILogger logger,
22+
/// [TagName("my.custom.tagname")] string name);
23+
/// </code>
24+
/// </example>
1525
/// <seealso cref="LoggerMessageAttribute"/>
1626
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
1727
[Conditional("CODE_GENERATION_ATTRIBUTES")]
18-
[Experimental(diagnosticId: DiagnosticIds.Experiments.Telemetry, UrlFormat = DiagnosticIds.UrlFormat)]
1928
public sealed class TagNameAttribute : Attribute
2029
{
2130
/// <summary>

src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Microsoft.Extensions.Telemetry.Abstractions.json

+16
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,22 @@
764764
}
765765
]
766766
},
767+
{
768+
"Type": "sealed class Microsoft.Extensions.Logging.TagNameAttribute : System.Attribute",
769+
"Stage": "Stable",
770+
"Methods": [
771+
{
772+
"Member": "Microsoft.Extensions.Logging.TagNameAttribute.TagNameAttribute(string name);",
773+
"Stage": "Stable"
774+
}
775+
],
776+
"Properties": [
777+
{
778+
"Member": "string Microsoft.Extensions.Logging.TagNameAttribute.Name { get; }",
779+
"Stage": "Stable"
780+
}
781+
]
782+
},
767783
{
768784
"Type": "sealed class Microsoft.Extensions.Diagnostics.Metrics.TagNameAttribute : System.Attribute",
769785
"Stage": "Stable",

src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ internal static partial void LogNewTemperature(ILogger<Program> logger, [LogProp
4343
internal record Temperature(double value, TemperatureUnit unit);
4444
```
4545

46+
The `TagName` attribute can be used to specify a custom tag name for each parameter or property. This is useful when you want to have more control over the naming of tags in your logs.
47+
48+
```csharp
49+
[LoggerMessage(1, LogLevel.Information, "My custom tag name: {my.custom.tagname}")]
50+
public static partial void LogMyCustomTagName(
51+
this ILogger logger,
52+
[TagName("my.custom.tagname")] string name);
53+
```
54+
4655
### Log Enrichment
4756

4857
Logging data can be enriched by adding custom log enrichers to the service collection. This can be done using specific implementations or generic types.

0 commit comments

Comments
 (0)