summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Diagnostics/LogSwitch.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Diagnostics/LogSwitch.cs')
-rw-r--r--src/mscorlib/src/System/Diagnostics/LogSwitch.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/mscorlib/src/System/Diagnostics/LogSwitch.cs b/src/mscorlib/src/System/Diagnostics/LogSwitch.cs
new file mode 100644
index 0000000000..a03c65abe1
--- /dev/null
+++ b/src/mscorlib/src/System/Diagnostics/LogSwitch.cs
@@ -0,0 +1,141 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+namespace System.Diagnostics {
+ using System;
+ using System.IO;
+ using System.Collections;
+ using System.Runtime.Versioning;
+ using System.Diagnostics.Contracts;
+ using System.Diagnostics.CodeAnalysis;
+
+ [Serializable]
+ internal class LogSwitch
+ {
+ // ! WARNING !
+ // If any fields are added/deleted/modified, perform the
+ // same in the EE code (debugdebugger.cpp/debugdebugger.h)
+ internal String strName;
+ internal String strDescription;
+ private LogSwitch ParentSwitch;
+ internal volatile LoggingLevels iLevel;
+ internal volatile LoggingLevels iOldLevel;
+
+ // ! END WARNING !
+
+
+ private LogSwitch ()
+ {
+ }
+
+ // Constructs a LogSwitch. A LogSwitch is used to categorize log messages.
+ //
+ // All switches (except for the global LogSwitch) have a parent LogSwitch.
+ //
+ [System.Security.SecuritySafeCritical] // auto-generated
+ public LogSwitch(String name, String description, LogSwitch parent)
+ {
+ if (name != null && name.Length == 0)
+ throw new ArgumentOutOfRangeException("Name", Environment.GetResourceString("Argument_StringZeroLength"));
+ Contract.EndContractBlock();
+
+ if ((name != null) && (parent != null))
+ {
+ strName = name;
+ strDescription = description;
+ iLevel = LoggingLevels.ErrorLevel;
+ iOldLevel = iLevel;
+ ParentSwitch = parent;
+
+ Log.m_Hashtable.Add (strName, this);
+
+ // Call into the EE to let it know about the creation of
+ // this switch
+ Log.AddLogSwitch (this);
+ }
+ else
+ throw new ArgumentNullException ((name==null ? "name" : "parent"));
+ }
+
+ [System.Security.SecuritySafeCritical] // auto-generated
+ internal LogSwitch(String name, String description)
+ {
+ strName = name;
+ strDescription = description;
+ iLevel = LoggingLevels.ErrorLevel;
+ iOldLevel = iLevel;
+ ParentSwitch = null;
+
+ Log.m_Hashtable.Add (strName, this);
+
+ // Call into the EE to let it know about the creation of
+ // this switch
+ Log.AddLogSwitch (this);
+ }
+
+
+ // Get property returns the name of the switch
+ public virtual String Name
+ {
+ get { return strName;}
+ }
+
+ // Get property returns the description of the switch
+ public virtual String Description
+ {
+ get {return strDescription;}
+ }
+
+
+ // Get property returns the parent of the switch
+ public virtual LogSwitch Parent
+ {
+ get { return ParentSwitch; }
+ }
+
+
+ // Property to Get/Set the level of log messages which are "on" for the switch.
+ //
+ public virtual LoggingLevels MinimumLevel
+ {
+ get { return iLevel; }
+ [System.Security.SecuritySafeCritical] // auto-generated
+ set
+ {
+ iLevel = value;
+ iOldLevel = value;
+ String strParentName = ParentSwitch!=null ? ParentSwitch.Name : "";
+ if (Debugger.IsAttached)
+ Log.ModifyLogSwitch ((int)iLevel, strName, strParentName);
+
+ Log.InvokeLogSwitchLevelHandlers (this, iLevel);
+ }
+ }
+
+
+ // Checks if the given level is "on" for this switch or one of its parents.
+ //
+ public virtual bool CheckLevel(LoggingLevels level)
+ {
+ if (iLevel > level)
+ {
+ // recurse through the list till parent is hit.
+ if (this.ParentSwitch == null)
+ return false;
+ else
+ return this.ParentSwitch.CheckLevel (level);
+ }
+ else
+ return true;
+ }
+
+
+ // Returns a switch with the particular name, if any. Returns null if no
+ // such switch exists.
+ public static LogSwitch GetSwitch(String name)
+ {
+ return (LogSwitch)Log.m_Hashtable[name];
+ }
+
+ }
+}