[Logging] TagName and TagProvider attributes don't work when applied to properties
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 894
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 23
Description
### Description
The `TagName` or `TagProvider` attributes don't work when applied to a class property. The output of a log method that uses these properties is as if you didn't use them.
When fixing this bug we should ensure that the functionality of the attributes also works when you apply them on a property of an object located in an assembly different from the log method. There was a bug #6598 with other log attributes, we should ensure that we'll not have the same bug for the `TagName` and `TagProvider` attributes.
### Reproduction Steps
**Demo.csproj**
```xml
Exe
net8.0
enable
enable
```
**Log.cs**
```cs
using Microsoft.Extensions.Logging;
internal static partial class Log
{
[LoggerMessage(LogLevel.Information)]
public static partial void LogObject(this ILogger logger, [LogProperties] ObjectToLog objectToLog);
}
public class ObjectToLog
{
[TagName("property.to.log")]
public string? PropertyToLog { get; set; } = "foo";
[TagProvider(typeof(TagProvider), nameof(TagProvider.RecordTags))]
public Property Property { get; set; } = new Property();
}
public class Property
{
public string? Value { get; set; } = "default";
}
internal static class TagProvider
{
public static void RecordTags(ITagCollector collector, Property property)
{
collector.Add("prop-val", property.Value);
}
}
```
**Program.cs**
```cs
using Microsoft.Extensions.Logging;
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddJsonConsole(options => options.JsonWriterOptions = new() { Indented = true });
});
ILogger logger = loggerFactory.CreateLogger("Demo");
logger.LogObject(new ObjectToLog());
```
### Expected behavior
Expected output:
```output
"prop-val": "default",
"objectToLog.property.to.log": "foo"
```
### Actual behavior
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
_No response_
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.