We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Diagnostics
- {
- using System;
- using System.IO;
- using System.Collections;
-
- [Serializable()]
- internal class LogSwitch
- {
-
-
-
- internal string strName;
- internal string strDescription;
- private LogSwitch ParentSwitch;
- private LogSwitch[] ChildSwitch;
- internal LoggingLevels iLevel;
- internal LoggingLevels iOldLevel;
- private int iNumChildren;
- private int iChildArraySize;
-
-
-
-
- private LogSwitch()
- {
- }
-
-
-
-
-
- public LogSwitch(string name, string description, LogSwitch parent)
- {
- if ((name != null) && (parent != null)) {
- if (name.Length == 0)
- throw new ArgumentOutOfRangeException("Name", Environment.GetResourceString("Argument_StringZeroLength"));
-
- strName = name;
- strDescription = description;
- iLevel = LoggingLevels.ErrorLevel;
- iOldLevel = iLevel;
-
-
- parent.AddChildSwitch(this);
-
- ParentSwitch = parent;
-
- ChildSwitch = null;
- iNumChildren = 0;
- iChildArraySize = 0;
-
- Log.m_Hashtable.Add(strName, this);
-
-
-
- Log.AddLogSwitch(this);
-
-
- Log.iNumOfSwitches++;
- }
- else
- throw new ArgumentNullException((name == null ? "name" : "parent"));
- }
-
- internal LogSwitch(string name, string description)
- {
- strName = name;
- strDescription = description;
- iLevel = LoggingLevels.ErrorLevel;
- iOldLevel = iLevel;
- ParentSwitch = null;
- ChildSwitch = null;
- iNumChildren = 0;
- iChildArraySize = 0;
-
- Log.m_Hashtable.Add(strName, this);
-
-
-
- Log.AddLogSwitch(this);
-
-
- Log.iNumOfSwitches++;
- }
-
-
-
- public virtual string Name {
- get { return strName; }
- }
-
-
- public virtual string Description {
- get { return strDescription; }
- }
-
-
-
- public virtual LogSwitch Parent {
- get { return ParentSwitch; }
- }
-
-
-
-
- public virtual LoggingLevels MinimumLevel {
- get { return iLevel; }
- set {
- iLevel = value;
- iOldLevel = value;
- string strParentName = ParentSwitch != null ? ParentSwitch.Name : "";
- if (Debugger.IsAttached)
- Log.ModifyLogSwitch((int)iLevel, strName, strParentName);
-
- Log.InvokeLogSwitchLevelHandlers(this, iLevel);
- }
- }
-
-
-
-
- public virtual bool CheckLevel(LoggingLevels level)
- {
- if (iLevel > level) {
-
- if (this.ParentSwitch == null)
- return false;
- else
- return this.ParentSwitch.CheckLevel(level);
- }
- else
- return true;
- }
-
-
-
-
- public static LogSwitch GetSwitch(string name)
- {
- return (LogSwitch)Log.m_Hashtable[name];
- }
-
- private void AddChildSwitch(LogSwitch child)
- {
- if (iChildArraySize <= iNumChildren) {
- int iIncreasedSize;
-
- if (iChildArraySize == 0)
- iIncreasedSize = 10;
- else
- iIncreasedSize = (iChildArraySize * 3) / 2;
-
-
- LogSwitch[] newChildSwitchArray = new LogSwitch[iIncreasedSize];
-
-
- if (iNumChildren > 0)
- Array.Copy(ChildSwitch, newChildSwitchArray, iNumChildren);
-
- iChildArraySize = iIncreasedSize;
-
- ChildSwitch = newChildSwitchArray;
- }
-
- ChildSwitch[iNumChildren++] = child;
- }
-
-
- }
- }