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)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 namespace System.Diagnostics
37 public class TraceSwitch : Switch
39 public TraceSwitch(string displayName, string description)
40 : base(displayName, description)
44 public TraceLevel Level {
45 get {return (TraceLevel) SwitchSetting;}
47 if (!Enum.IsDefined (typeof(TraceLevel), value))
48 throw new ArgumentException ("value");
49 SwitchSetting = (int) value;
53 public bool TraceError {
54 get {return SwitchSetting >= (int) TraceLevel.Error;}
57 public bool TraceWarning {
58 get {return SwitchSetting >= (int) TraceLevel.Warning;}
61 public bool TraceInfo {
62 get {return SwitchSetting >= (int) TraceLevel.Info;}
65 public bool TraceVerbose {
66 get {return SwitchSetting >= (int) TraceLevel.Verbose;}
69 // .NET accepts values over 4; they're equivalent to TraceLevel.Verbose
70 // For -1, .NET crashes. (Oops!) Other negative numbers work with an
71 // equivalent to setting SwitchSetting to TraceLevel.Off.
72 // The logic for the accessors will cope with values >= 4, so we'll just
73 // check for negative numbers.
74 protected override void OnSwitchSettingChanged()
76 if (SwitchSetting < 0)
77 SwitchSetting = (int) TraceLevel.Off;