private void AddTraceListener(IDictionary d, XmlNode child, XmlAttributeCollection attributes, TraceListenerCollection listeners)
{
string name = GetAttribute(attributes, "name", true, child);
string type = null;
#if CONFIGURATION_DEP
type = GetAttribute(attributes, "type", false, child);
if (type == null)
{
// indicated by name.
TraceListener shared = GetSharedListeners(d) [name];
if (shared == null)
{
throw new ConfigurationException(String.Format("Shared trace listener {0} does not exist.", name));
}
if (attributes.Count != 0)
{
throw new ConfigurationErrorsException(string.Format(
"Listener '{0}' references a shared " +
"listener and can only have a 'Name' " +
"attribute.", name));
}
listeners.Add(shared, configValues);
return;
}
#else
type = GetAttribute(attributes, "type", true, child);
#endif
Type t = Type.GetType(type);
if (t == null)
{
throw new ConfigurationException(string.Format("Invalid Type Specified: {0}", type));
}
object[] args;
Type[] types;
string initializeData = GetAttribute(attributes, "initializeData", false, child);
if (initializeData != null)
{
args = new object[] { initializeData };
types = new Type[] { typeof(string) };
}
else
{
args = null;
types = Type.EmptyTypes;
}
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
if (t.Assembly == GetType().Assembly)
{
flags |= BindingFlags.NonPublic;
}
ConstructorInfo ctor = t.GetConstructor(flags, null, types, null);
if (ctor == null)
{
throw new ConfigurationException("Couldn't find constructor for class " + type);
}
TraceListener l = (TraceListener)ctor.Invoke(args);
l.Name = name;
#if CONFIGURATION_DEP
string trace = GetAttribute(attributes, "traceOutputOptions", false, child);
if (trace != null)
{
if (trace != trace.Trim())
{
throw new ConfigurationErrorsException(string.Format(
"Invalid value '{0}' for 'traceOutputOptions'.",
trace), child);
}
TraceOptions trace_options;
try {
trace_options = (TraceOptions)Enum.Parse(
typeof(TraceOptions), trace);
} catch (ArgumentException) {
throw new ConfigurationErrorsException(string.Format(
"Invalid value '{0}' for 'traceOutputOptions'.",
trace), child);
}
l.TraceOutputOptions = trace_options;
}
string [] supported_attributes = l.GetSupportedAttributes();
if (supported_attributes != null)
{
for (int i = 0; i < supported_attributes.Length; i++)
{
string key = supported_attributes [i];
string value = GetAttribute(attributes, key, false, child);
if (value != null)
{
l.Attributes.Add(key, value);
}
}
}
#endif
listeners.Add(l, configValues);
}