-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
When configuring trace listeners for System.Diagnostics.Trace using an XML configuration file (e.g., <Listeners> or <SharedListener> elements), it should be possible to add custom attributes for TraceListener implementations. These custom attributes should be added to the TraceListener.Attributes property. However, after deserializing the configuration file, the Attributes property remains empty.
The issue arises due to a missing assignment in the ListenerElement, specifically in the following code block:
public StringDictionary Attributes => _attributes ?? new StringDictionary();Here, the Attributes property is never populated correctly, as a new StringDictionary is always created.
Reproduction Steps
- Create an app.config file that configures a
DelimitedListTraceListenerand specifies a custom delimiter using theAttributesproperty:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add name="delimited" type="System.Diagnostics.DelimitedListTraceListener" initializeData="test.log" delimiter=":" />
</listeners>
</trace>
</system.diagnostics>
</configuration>-
Apply the configuration using
TraceConfiguration.Register(). -
Check the
Delimiterproperty on the listener:
var listener = (DelimitedListTraceListener)Trace.Listeners["delimited"];
Assert.Equal(":", listener.Delimiter); // This assertion fails; the default value ";" is returned.Expected behavior
TraceListener.Attributes property must be populated with unknown attributes from the XML configuration.
Actual behavior
TraceListener.Attributes is always empty.
Regression?
Works in .NET Framework.
Known Workarounds
No response
Configuration
.NET 8
Other information
No response