상속: TypedElement
        internal void InitializeDefaultInternal() {
            ListenerElement defaultListener = new ListenerElement(false);
            defaultListener.Name = "Default";
            defaultListener.TypeName = typeof(DefaultTraceListener).FullName;
            defaultListener._isAddedByDefault = true;

            this.BaseAdd(defaultListener);
        }
 internal void InitializeDefaultInternal()
 {
     ListenerElement element = new ListenerElement(false) {
         Name = "Default",
         TypeName = typeof(DefaultTraceListener).FullName,
         _isAddedByDefault = true
     };
     this.BaseAdd(element);
 }
        public TraceListener GetRuntimeObject()
        {
            if (_runtimeObject != null)
            {
                return((TraceListener)_runtimeObject);
            }

            try {
                string className = TypeName;
                if (String.IsNullOrEmpty(className))
                {
                    // Look it up in SharedListeners
                    Debug.Assert(_allowReferences, "_allowReferences must be true if type name is null");

                    if (_attributes != null || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || TraceOutputOptions != TraceOptions.None || !String.IsNullOrEmpty(InitData))
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_listener_cant_have_properties, Name));
                    }

                    if (DiagnosticsConfiguration.SharedListeners == null)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
                    }

                    ListenerElement sharedListener = DiagnosticsConfiguration.SharedListeners[Name];
                    if (sharedListener == null)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
                    }
                    else
                    {
                        _runtimeObject = sharedListener.GetRuntimeObject();
                        return((TraceListener)_runtimeObject);
                    }
                }
                else
                {
                    // create a new one
                    TraceListener newListener = (TraceListener)BaseGetRuntimeObject();
                    newListener.initializeData = InitData;
                    newListener.Name           = Name;
                    newListener.SetAttributes(Attributes);
                    newListener.TraceOutputOptions = TraceOutputOptions;

                    if ((Filter != null) && (Filter.TypeName != null) && (Filter.TypeName.Length != 0))
                    {
                        newListener.Filter = Filter.GetRuntimeObject();
                    }

                    _runtimeObject = newListener;
                    return(newListener);
                }
            }
            catch (ArgumentException e) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, Name), e);
            }
        }
        internal void InitializeDefaultInternal()
        {
            ListenerElement defaultListener = new ListenerElement(false);

            defaultListener.Name              = "Default";
            defaultListener.TypeName          = typeof(DefaultTraceListener).FullName;
            defaultListener._isAddedByDefault = true;

            BaseAdd(defaultListener);
        }
예제 #5
0
        public override bool Equals(object compareTo)
        {
            if (!this.Name.Equals("Default") || !this.TypeName.Equals(typeof(DefaultTraceListener).FullName))
            {
                return(base.Equals(compareTo));
            }
            ListenerElement element = compareTo as ListenerElement;

            return(((element != null) && element.Name.Equals("Default")) && element.TypeName.Equals(typeof(DefaultTraceListener).FullName));
        }
예제 #6
0
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);
            ListenerElement element = sourceElement as ListenerElement;

            if ((element != null) && (element._attributes != null))
            {
                this._attributes = element._attributes;
            }
        }
        internal void InitializeDefaultInternal()
        {
            ListenerElement element = new ListenerElement(false)
            {
                Name              = "Default",
                TypeName          = typeof(DefaultTraceListener).FullName,
                _isAddedByDefault = true
            };

            this.BaseAdd(element);
        }
        protected override void BaseAdd(ConfigurationElement element)
        {
            ListenerElement element2 = element as ListenerElement;

            if (element2.Name.Equals("Default") && element2.TypeName.Equals(typeof(DefaultTraceListener).FullName))
            {
                base.BaseAdd(element2, false);
            }
            else
            {
                base.BaseAdd(element2, this.ThrowOnDuplicate);
            }
        }
        protected override void Unmerge(ConfigurationElement sourceElement,
                                        ConfigurationElement parentElement,
                                        ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);

            // Unmerge the optional attributes cache as well
            ListenerElement le = sourceElement as ListenerElement;

            if ((le != null) && (le._attributes != null))
            {
                this._attributes = le._attributes;
            }
        }
예제 #10
0
        internal TraceListener RefreshRuntimeObject(TraceListener listener)
        {
            TraceListener listener2;

            base._runtimeObject = null;
            try
            {
                string typeName = this.TypeName;
                if (string.IsNullOrEmpty(typeName))
                {
                    if (((this._attributes != null) || (base.ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere)) || ((this.TraceOutputOptions != TraceOptions.None) || !string.IsNullOrEmpty(base.InitData)))
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_listener_cant_have_properties", new object[] { this.Name }));
                    }
                    if (DiagnosticsConfiguration.SharedListeners == null)
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_to_nonexistent_listener", new object[] { this.Name }));
                    }
                    ListenerElement element = DiagnosticsConfiguration.SharedListeners[this.Name];
                    if (element == null)
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_to_nonexistent_listener", new object[] { this.Name }));
                    }
                    base._runtimeObject = element.RefreshRuntimeObject(listener);
                    return((TraceListener)base._runtimeObject);
                }
                if ((Type.GetType(typeName) != listener.GetType()) || (base.InitData != listener.initializeData))
                {
                    return(this.GetRuntimeObject());
                }
                listener.SetAttributes(this.Attributes);
                listener.TraceOutputOptions = this.TraceOutputOptions;
                if ((base.ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere) || (base.ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.Inherited))
                {
                    listener.Filter = this.Filter.RefreshRuntimeObject(listener.Filter);
                }
                else
                {
                    listener.Filter = null;
                }
                base._runtimeObject = listener;
                listener2           = listener;
            }
            catch (ArgumentException exception)
            {
                throw new ConfigurationErrorsException(System.SR.GetString("Could_not_create_listener", new object[] { this.Name }), exception);
            }
            return(listener2);
        }
        protected override void BaseAdd(ConfigurationElement element)
        {
            ListenerElement listenerElement = element as ListenerElement;

            Debug.Assert((listenerElement != null), "adding elements other than ListenerElement to ListenerElementsCollection?");

            if (listenerElement.Name.Equals("Default") && listenerElement.TypeName.Equals(typeof(DefaultTraceListener).FullName))
            {
                BaseAdd(listenerElement, false);
            }
            else
            {
                BaseAdd(listenerElement, ThrowOnDuplicate);
            }
        }
 public override bool Equals(object compareTo)
 {
     if (this.Name.Equals("Default") && this.TypeName.Equals(typeof(DefaultTraceListener).FullName))
     {
         // This is a workaround to treat all DefaultTraceListener named 'Default' the same.
         // This is needed for the Config.Save to work properly as otherwise config base layers
         // above us would run into duplicate 'Default' listener element and perceive it as
         // error.
         ListenerElement compareToElem = compareTo as ListenerElement;
         return((compareToElem != null) && compareToElem.Name.Equals("Default") &&
                compareToElem.TypeName.Equals(typeof(DefaultTraceListener).FullName));
     }
     else
     {
         return(base.Equals(compareTo));
     }
 }
예제 #13
0
        public TraceListener GetRuntimeObject()
        {
            TraceListener listener2;

            if (base._runtimeObject != null)
            {
                return((TraceListener)base._runtimeObject);
            }
            try
            {
                if (string.IsNullOrEmpty(this.TypeName))
                {
                    if (((this._attributes != null) || (base.ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere)) || ((this.TraceOutputOptions != TraceOptions.None) || !string.IsNullOrEmpty(base.InitData)))
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_listener_cant_have_properties", new object[] { this.Name }));
                    }
                    if (DiagnosticsConfiguration.SharedListeners == null)
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_to_nonexistent_listener", new object[] { this.Name }));
                    }
                    ListenerElement element = DiagnosticsConfiguration.SharedListeners[this.Name];
                    if (element == null)
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("Reference_to_nonexistent_listener", new object[] { this.Name }));
                    }
                    base._runtimeObject = element.GetRuntimeObject();
                    return((TraceListener)base._runtimeObject);
                }
                TraceListener listener = (TraceListener)base.BaseGetRuntimeObject();
                listener.initializeData = base.InitData;
                listener.Name           = this.Name;
                listener.SetAttributes(this.Attributes);
                listener.TraceOutputOptions = this.TraceOutputOptions;
                if (((this.Filter != null) && (this.Filter.TypeName != null)) && (this.Filter.TypeName.Length != 0))
                {
                    listener.Filter = this.Filter.GetRuntimeObject();
                }
                base._runtimeObject = listener;
                listener2           = listener;
            }
            catch (ArgumentException exception)
            {
                throw new ConfigurationErrorsException(System.SR.GetString("Could_not_create_listener", new object[] { this.Name }), exception);
            }
            return(listener2);
        }
        internal TraceListener RefreshRuntimeObject(TraceListener listener)
        {
            _runtimeObject = null;
            try {
                string className = TypeName;
                if (String.IsNullOrEmpty(className))
                {
                    // Look it up in SharedListeners and ask the sharedListener to refresh.
                    Debug.Assert(_allowReferences, "_allowReferences must be true if type name is null");

                    if (_attributes != null || ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere || TraceOutputOptions != TraceOptions.None || !String.IsNullOrEmpty(InitData))
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_listener_cant_have_properties, Name));
                    }

                    if (DiagnosticsConfiguration.SharedListeners == null)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
                    }

                    ListenerElement sharedListener = DiagnosticsConfiguration.SharedListeners[Name];
                    if (sharedListener == null)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Reference_to_nonexistent_listener, Name));
                    }
                    else
                    {
                        _runtimeObject = sharedListener.RefreshRuntimeObject(listener);
                        return((TraceListener)_runtimeObject);
                    }
                }
                else
                {
                    // We're the element with the type and initializeData info.  First see if those two are the same as they were.
                    // If not, create a whole new object, otherwise, just update the other properties.
                    if (Type.GetType(className) != listener.GetType() || InitData != listener.initializeData)
                    {
                        // type or initdata changed
                        return(GetRuntimeObject());
                    }
                    else
                    {
                        listener.SetAttributes(Attributes);
                        listener.TraceOutputOptions = TraceOutputOptions;

                        if (ElementInformation.Properties[_propFilter.Name].ValueOrigin == PropertyValueOrigin.SetHere)
                        {
                            listener.Filter = Filter.RefreshRuntimeObject(listener.Filter);
                        }
                        else
                        {
                            listener.Filter = null;
                        }

                        _runtimeObject = listener;
                        return(listener);
                    }
                }
            }
            catch (ArgumentException e) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, Name), e);
            }
        }