private void AddTraceListener(IDictionary d, XElement child, IDictionary <string, XAttribute> 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 (child.HasAttributes)
                {
                    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

#if SSHARP
            CType t = Type.GetType(type);
#else
            Type t = Type.GetType(type);
#endif
            if (t == null)
            {
                throw new ConfigurationException(string.Format("Invalid Type Specified: {0}", type));
            }

            object[] args;
#if SSHARP
            CType[] types;
#else
            Type[] types;
#endif

            string initializeData = GetAttribute(attributes, "initializeData", false, child);
            if (initializeData != null)
            {
                args = new object[] { initializeData };
#if SSHARP
                types = new CType[] { typeof(string) };
#else
                types = new Type[] { typeof(string) };
#endif
            }
            else
            {
                args = null;
#if NETCF
#if SSHARP
                types = new CType[0];
#else
                types = new Type[0];
#endif
#else
                types = Type.EmptyTypes;
#endif
            }
#if SSHARP
            var ctor = t.GetConstructor(types);
#else
            BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
            if (t.Assembly == GetType().Assembly)
            {
                flags |= BindingFlags.NonPublic;
            }

            ConstructorInfo ctor = t.GetConstructor(flags, null, types, null);
#endif
            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, false);
                }
                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);
        }