diff options
author | Jonathan Pryor <jpryor@novell.com> | 2005-01-18 16:25:34 +0300 |
---|---|---|
committer | Jonathan Pryor <jpryor@novell.com> | 2005-01-18 16:25:34 +0300 |
commit | 998e1fc3c98172e00b7a2c40d8f2dcd250d3d23f (patch) | |
tree | 95c18ee58120aab5e93fb0a6f211947a79a83048 /mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs | |
parent | ec09034a834fff603dc82bbd45a6291c960d175b (diff) |
Implement the .NET 1.1 requirement that the
/system.diagnostics/switch/add/@value attribute only contain numeric data and
some other fixes (thread-safety in the Debug- and Trace-related classes).
* System/System.Diagnostics/DiagnosticsConfigurationHandler.cs
(DiagnosticsConfiguration): Don't read the .config file from the
static ctor (again), as if it fails we'll get a TypeLoadException -- bad! Instead, lazy-read the .config file.
* System/System.Diagnostics/DiagnosticsConfigurationHandler.cs
(DiagnosticsConfigurationHandler): Require that the /switch/add/@value
attribute contains only numeric values.
* System/System.Diagnostics/DiagnosticsConfigurationHandler.cs:
* System/System.Diagnostics/TraceImpl.cs: Don't initialize everything in
the static ctor, as if it fails (due to an invalid .confg file) we get a
TypeLoadException, while .NET generates a ConfigurationException.
Instead, initialize everything the first time the Listeners property is
accessed, which allows the static ctor to run without chance of failure,
avoiding the TypeLoadException.
* System/System.Diagnostics/TraceListenerCollection.cs: This should be
thread-safe, as it's accessible from a static member of TraceImpl
(available through the public Debug and Trace classes).
* System/System.Diagnostics/Switch.cs: Leave the original switch value alone.
If it isn't valid (i.e. numeric), the DiagnosticsConfigurationHandler
will catch it.
* System/Test/test-config-file: Remove "string-value" switch, as it causes
ConfigurationExceptions under .NET 1.1 (the value attribute can't be
non-numeric), and Mono now follows this behavior. Add a "custom-switch"
value, which is used in the regression tests.
* System/Test/System.Diagnostics/DiagnosticsConfigurationHandlerTest.cs:
.NET 1.1 requires that the value attribute be a numeric value; check for
that and update the success test so that they'll actually pass.
* System/Test/System.Diagnostics/SwitchesTest.cs: TestNewSwitch reads
"custom-switch" now, and the switches value is now "42", not "0".
Remove warning about unused variable.
svn path=/trunk/mcs/; revision=39090
Diffstat (limited to 'mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs')
-rw-r--r-- | mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs index 2452a1c4e9f..54334aac9d8 100644 --- a/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs +++ b/mcs/class/System/System.Diagnostics/DiagnosticsConfigurationHandler.cs @@ -41,11 +41,15 @@ namespace System.Diagnostics { internal sealed class DiagnosticsConfiguration { - private static IDictionary settings = - (IDictionary) ConfigurationSettings.GetConfig ("system.diagnostics"); + private static object lock_ = new object(); + private static IDictionary settings; public static IDictionary Settings { get { + lock (lock_) { + if (settings == null) + settings = (IDictionary) ConfigurationSettings.GetConfig ("system.diagnostics"); + } return settings; } } @@ -150,7 +154,9 @@ namespace System.Diagnostics case "add": name = GetAttribute (attributes, "name", true, child); value = GetAttribute (attributes, "value", true, child); - newNodes[name] = AsString (value); + value = AsString (value); + ValidateIntegralValue (name, value); + newNodes [name] = value; break; case "remove": name = GetAttribute (attributes, "name", true, child); @@ -172,6 +178,20 @@ namespace System.Diagnostics d [node.Name] = newNodes; } + private static void ValidateIntegralValue (string name, string value) + { + try { + int n = int.Parse (value); + // remove warning about unused variable. + n = n; + } + catch { + throw new ConfigurationException (string.Format ( + "Error in '{0}': " + + "The value of a switch must be integral", name)); + } + } + private void AddTraceNode (IDictionary d, XmlNode node) { AddTraceAttributes (d, node); |