12 private SwitchElementsCollection switchSettings;
14 private readonly
string description;
16 private readonly
string displayName;
18 private int switchSetting;
20 private volatile bool initialized;
22 private bool initializing;
24 private volatile string switchValueString =
string.Empty;
28 private string defaultValue;
32 private static int s_LastCollectionCount;
42 if (attributes ==
null)
60 if (description !=
null)
74 if (!initialized && InitializeWithStatus())
83 lock (TraceInternal.critSec)
86 if (switchSetting != value)
88 switchSetting = value;
102 protected string Value 107 return switchValueString;
112 switchValueString = value;
119 throw new ConfigurationErrorsException(SR.GetString(
"BadConfigSwitchValue",
DisplayName), inner);
123 throw new ConfigurationErrorsException(SR.GetString(
"BadConfigSwitchValue",
DisplayName), inner2);
127 throw new ConfigurationErrorsException(SR.GetString(
"BadConfigSwitchValue",
DisplayName), inner3);
135 protected Switch(
string displayName,
string description)
136 : this(displayName, description,
"0")
144 protected Switch(
string displayName,
string description,
string defaultSwitchValue)
146 if (displayName ==
null)
148 displayName =
string.Empty;
150 this.displayName = displayName;
151 this.description = description;
154 _pruneCachedSwitches();
157 defaultValue = defaultSwitchValue;
160 private static void _pruneCachedSwitches()
167 for (
int i = 0; i < switches.
Count; i++)
172 list.Add(switches[i]);
175 if (list.Count < switches.
Count)
181 s_LastCollectionCount = GC.CollectionCount(2);
186 private void Initialize()
188 InitializeWithStatus();
191 private bool InitializeWithStatus()
195 lock (TraceInternal.critSec)
197 if (initialized || initializing)
202 if (switchSettings ==
null && !InitializeConfigSettings())
205 initializing =
false;
208 if (switchSettings !=
null)
210 SwitchElement switchElement = switchSettings[displayName];
211 if (switchElement !=
null)
213 string value = switchElement.Value;
220 Value = defaultValue;
229 initializing =
false;
233 attributes.ReplaceHashtable(switchElement.Attributes);
237 switchValueString = defaultValue;
243 switchValueString = defaultValue;
247 initializing =
false;
253 private bool InitializeConfigSettings()
255 if (switchSettings !=
null)
259 if (!DiagnosticsConfiguration.CanInitialize())
263 switchSettings = DiagnosticsConfiguration.SwitchSettings;
285 internal static void RefreshAll()
289 _pruneCachedSwitches();
290 for (
int i = 0; i < switches.
Count; i++)
292 ((
Switch)switches[i].Target)?.Refresh();
297 internal void Refresh()
299 lock (TraceInternal.critSec)
302 switchSettings =
null;
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
virtual void OnValueChanged()
Invoked when the P:System.Diagnostics.Switch.Value property is changed.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.List`1.
virtual internal string [] GetSupportedAttributes()
Gets the custom attributes supported by the switch.
Switch(string displayName, string description, string defaultSwitchValue)
Initializes a new instance of the T:System.Diagnostics.Switch class, specifying the display name,...
Implements a hash table with the key and the value strongly typed to be strings rather than objects.
The exception that is thrown when an arithmetic, casting, or conversion operation in a checked contex...
Represents a weak reference, which references an object while still allowing that object to be reclai...
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
Switch(string displayName, string description)
Initializes a new instance of the T:System.Diagnostics.Switch class.
void AddRange(IEnumerable< T > collection)
Adds the elements of the specified collection to the end of the T:System.Collections....
string Value
Gets or sets the value of the switch.
The exception that is thrown when a configuration system error has occurred.
Controls the system garbage collector, a service that automatically reclaims unused memory.
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual void OnSwitchSettingChanged()
Invoked when the P:System.Diagnostics.Switch.SwitchSetting property is changed.
void Clear()
Removes all elements from the T:System.Collections.Generic.List`1.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
int SwitchSetting
Gets or sets the current setting for this switch.
static int CollectionCount(int generation)
Returns the number of times garbage collection has occurred for the specified generation of objects.
void TrimExcess()
Sets the capacity to the actual number of elements in the T:System.Collections.Generic....
StringDictionary Attributes
Gets the custom switch attributes defined in the application configuration file.
Provides information about a specific culture (called a locale for unmanaged code development)....
Provides an abstract base class to create new debugging and tracing switches.
string DisplayName
Gets a name used to identify the switch.
string Description
Gets a description of the switch.