2004-05-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System / System.Diagnostics / TraceSwitch.cs
index 4b64d80e6ce78f4f5b454967f19773f34e97d746..3ddc37141df40965d16b2677eea9534ea3b01a09 100755 (executable)
@@ -1,97 +1,60 @@
 //
 // System.Diagnostics.TraceSwtich.cs
 //
+// Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation 
+// can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
+//
 // Author:
 //     John R. Hicks (angryjohn69@nc.rr.com)
+//     Jonathan Pryor (jonpryor@vt.edu)
 //
-// (C) 2001
+// (C) 2001-2002
 //
 
 namespace System.Diagnostics
 {
-       /// <summary>
-       /// Multi-level switch to provide tracing and debug output without
-       /// recompiling.
-       /// </summary>
        public class TraceSwitch : Switch
        {
-               private TraceLevel level;
-               private bool traceError = false;
-               private bool traceInfo = false;
-               private bool traceVerbose = false;
-               private bool traceWarning = false;
-
-               /// <summary>
-               /// Initializes a new instance
-               /// </summary>
-               /// <param name="displayName">Name for the switch</param>
-               /// <param name="description">Description of the switch</param>
                public TraceSwitch(string displayName, string description)
                        : base(displayName, description)
                {
                }
 
-               /// <summary>
-               /// Gets or sets the trace level that specifies the messages to 
-               /// output for tracing and debugging.
-               /// </summary>
-               public TraceLevel Level
-               {
-                       get 
-                       {
-                               return level;
-                       }
-                       set
-                       {
-                               level = value;
+               public TraceLevel Level {
+                       get {return (TraceLevel) SwitchSetting;}
+                       set {
+                               if (!Enum.IsDefined (typeof(TraceLevel), value))
+                                       throw new ArgumentException ("value");
+                               SwitchSetting = (int) value;
                        }
+               }
 
+               public bool TraceError {
+                       get {return SwitchSetting >= (int) TraceLevel.Error;}
                }
 
-               /// <summary>
-               /// Gets a value indicating whether the Level is set to Error, 
-               /// Warning, Info, or Verbose.
-               /// </summary>
-               public bool TraceError
-               {
-                       get 
-                       {
-                               return traceError;
-                       }
+               public bool TraceWarning {
+                       get {return SwitchSetting >= (int) TraceLevel.Warning;}
                }
 
-               /// <summary>
-               /// Gets a value indicating whether the Level is set to Info or Verbose.
-               /// </summary>
-               public bool TraceInfo
-               {
-                       get 
-                       {
-                               return traceInfo;
-                       }
+               public bool TraceInfo {
+                       get {return SwitchSetting >= (int) TraceLevel.Info;}
                }
 
-               /// <summary>
-               /// Gets a value indicating whether the Level is set to Verbose.
-               /// </summary>
-               public bool TraceVerbose
-               {
-                       get 
-                       {
-                               return traceVerbose;
-                       }
+               public bool TraceVerbose {
+                       get {return SwitchSetting >= (int) TraceLevel.Verbose;}
                }
 
-               /// <summary>
-               /// Gets a value indicating whether the Level is set to
-               /// Warning, Info, or Verbose.
-               /// </summary>
-               public bool TraceWarning
+               // .NET accepts values over 4; they're equivalent to TraceLevel.Verbose
+               // For -1, .NET crashes.  (Oops!)  Other negative numbers work with an
+               // equivalent to setting SwitchSetting to TraceLevel.Off.
+               // The logic for the accessors will cope with values >= 4, so we'll just
+               // check for negative numbers.
+               protected override void OnSwitchSettingChanged()
                {
-                       get
-                       {
-                               return traceWarning;
-                       }
+                       if (SwitchSetting < 0)
+                               SwitchSetting = (int) TraceLevel.Off;
                }
        }
 }
+