3ddc37141df40965d16b2677eea9534ea3b01a09
[mono.git] / mcs / class / System / System.Diagnostics / TraceSwitch.cs
1 //
2 // System.Diagnostics.TraceSwtich.cs
3 //
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation 
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
6 //
7 // Author:
8 //      John R. Hicks (angryjohn69@nc.rr.com)
9 //      Jonathan Pryor (jonpryor@vt.edu)
10 //
11 // (C) 2001-2002
12 //
13
14 namespace System.Diagnostics
15 {
16         public class TraceSwitch : Switch
17         {
18                 public TraceSwitch(string displayName, string description)
19                         : base(displayName, description)
20                 {
21                 }
22
23                 public TraceLevel Level {
24                         get {return (TraceLevel) SwitchSetting;}
25                         set {
26                                 if (!Enum.IsDefined (typeof(TraceLevel), value))
27                                         throw new ArgumentException ("value");
28                                 SwitchSetting = (int) value;
29                         }
30                 }
31
32                 public bool TraceError {
33                         get {return SwitchSetting >= (int) TraceLevel.Error;}
34                 }
35
36                 public bool TraceWarning {
37                         get {return SwitchSetting >= (int) TraceLevel.Warning;}
38                 }
39
40                 public bool TraceInfo {
41                         get {return SwitchSetting >= (int) TraceLevel.Info;}
42                 }
43
44                 public bool TraceVerbose {
45                         get {return SwitchSetting >= (int) TraceLevel.Verbose;}
46                 }
47
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()
54                 {
55                         if (SwitchSetting < 0)
56                                 SwitchSetting = (int) TraceLevel.Off;
57                 }
58         }
59 }
60