2 // System.Diagnostics.TraceSwtich.cs
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
8 // John R. Hicks (angryjohn69@nc.rr.com)
9 // Jonathan Pryor (jonpryor@vt.edu)
14 namespace System.Diagnostics
16 public class TraceSwitch : Switch
18 public TraceSwitch(string displayName, string description)
19 : base(displayName, description)
23 public TraceLevel Level {
24 get {return (TraceLevel) SwitchSetting;}
26 if (!Enum.IsDefined (typeof(TraceLevel), value))
27 throw new ArgumentException ("value");
28 SwitchSetting = (int) value;
32 public bool TraceError {
33 get {return SwitchSetting >= (int) TraceLevel.Error;}
36 public bool TraceWarning {
37 get {return SwitchSetting >= (int) TraceLevel.Warning;}
40 public bool TraceInfo {
41 get {return SwitchSetting >= (int) TraceLevel.Info;}
44 public bool TraceVerbose {
45 get {return SwitchSetting >= (int) TraceLevel.Verbose;}
48 // .NET accepts values over 4; they're equivalent to TraceLevel.Verbose
49 // For -1, .NET crashes. (Oops!) Other negative numbers work with an
50 // equivalent to setting SwitchSetting to TraceLevel.Off.
51 // The logic for the accessors will cope with values >= 4, so we'll just
52 // check for negative numbers.
53 protected override void OnSwitchSettingChanged()
55 if (SwitchSetting < 0)
56 SwitchSetting = (int) TraceLevel.Off;