TraceSwitch.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // System.Diagnostics.TraceSwtich.cs
  3. //
  4. // Comments from John R. Hicks <[email protected]> original implementation
  5. // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
  6. //
  7. // Author:
  8. // John R. Hicks ([email protected])
  9. // Jonathan Pryor ([email protected])
  10. //
  11. // (C) 2001-2002
  12. //
  13. namespace System.Diagnostics
  14. {
  15. public class TraceSwitch : Switch
  16. {
  17. public TraceSwitch(string displayName, string description)
  18. : base(displayName, description)
  19. {
  20. }
  21. public TraceLevel Level {
  22. get {return (TraceLevel) SwitchSetting;}
  23. set {
  24. if (!Enum.IsDefined (typeof(TraceLevel), value))
  25. throw new ArgumentException ("value");
  26. SwitchSetting = (int) value;
  27. }
  28. }
  29. public bool TraceError {
  30. get {return SwitchSetting >= (int) TraceLevel.Error;}
  31. }
  32. public bool TraceWarning {
  33. get {return SwitchSetting >= (int) TraceLevel.Warning;}
  34. }
  35. public bool TraceInfo {
  36. get {return SwitchSetting >= (int) TraceLevel.Info;}
  37. }
  38. public bool TraceVerbose {
  39. get {return SwitchSetting >= (int) TraceLevel.Verbose;}
  40. }
  41. // .NET accepts values over 4; they're equivalent to TraceLevel.Verbose
  42. // For -1, .NET crashes. (Oops!) Other negative numbers work with an
  43. // equivalent to setting SwitchSetting to TraceLevel.Off.
  44. // The logic for the accessors will cope with values >= 4, so we'll just
  45. // check for negative numbers.
  46. protected override void OnSwitchSettingChanged()
  47. {
  48. if (SwitchSetting < 0)
  49. SwitchSetting = (int) TraceLevel.Off;
  50. }
  51. }
  52. }