So I have a custom trace listener which began it's life as this:
http://www.codeproject.com/Articles/30956/A-Rolling-XmlWriterTraceListener
I have modified this to work more like the Log4Net RollingFileAppender (see: http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.html)
When I run the code I find that it doesn't set the property / field values from the custom attributes in the config file.
Analysing the object at runtime reveals that the Attributes property (this.Attributes) contains nothing.
Any ideas how I would fix this?
Am I supposed to manually populate these or something?
Ok here's a code sample:
[HostProtection(Synchronization = true)]
public class RollingXmlWriterTraceListener : XmlWriterTraceListener
{
public RollingXmlWriterTraceListener(string filename)
: base(filename)
{
_basicTraceFileName = filename;
LoadAttributes();
}
In the LoadAttributes method i then do ...
if (Attributes.ContainsKey("maxTraceFileCount"))
{
string attributeValue = Attributes["maxTraceFileCount"];
The problem is "Attributes" never contains anything. This class instantiated from framework code using the config information which does contain the attributes...
<sharedListeners>
<add type="emedia.Common.Wcf.RollingXmlWriterTraceListener, emedia.Common.Wcf"
name="System.ServiceModel.XmlTrace.Listener"
traceOutputOptions="None"
initializeData="C:\Logs\MyTraceFileName.svclog"
MaxTraceFileSize="1048576"
MaxTraceFileCount="10"
/>
</sharedListeners>
Edit 2:
The XmlWriterTraceListener class is part of .Net, by making that my base class in Inherit the Attributes property.
In the config I should be able to specify any attribute then in the code do something like ...
var attValue = Attributes["something"];
... but for some reason this comes back null (the attribute is not in the collection).