Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BooleanSwitch Constructor (String, String)

Initializes a new instance of the BooleanSwitch class with the specified display name and description.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public BooleanSwitch (
	string displayName,
	string description
)
public BooleanSwitch (
	String displayName, 
	String description
)
public function BooleanSwitch (
	displayName : String, 
	description : String
)

Parameters

displayName

The name to display on a user interface.

description

The description of the switch.

When you create a BooleanSwitch, the displayName parameter is used to find initial switch settings. If the constructor cannot find initial settings, the Enabled property is set to false (disabled).

To set the level of your BooleanSwitch, edit the configuration file corresponding to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all switches previously set by the application. The configuration file should be formatted like the following example:

 <configuration>
     <system.diagnostics>
        <switches>
           <add name="mySwitch" value="10" />
           <add name="myNewSwitch" value="20" />
           <remove name="mySwitch" />
           <clear/>
        </switches>
     </system.diagnostics>
  </configuration>
NoteNote

The switches you created should be static.

The following example creates a BooleanSwitch and uses the switch to determine whether to print an error message. The switch is created at the class level. The Main method passes its location to MyMethod, which prints an error message and where the error occurred.

// Class level declaration.
/* Create a BooleanSwitch for data.*/
static BooleanSwitch dataSwitch = new BooleanSwitch("Data", "DataAccess module");

static public void MyMethod(string location) {
   //Insert code here to handle processing.
   if(dataSwitch.Enabled)
      Console.WriteLine("Error happened at " + location);
}

public static void Main(string[] args) {
   //Run the method which writes an error message specifying the location of the error.
   MyMethod("in Main");
}


// Class level declaration.
/* Create a BooleanSwitch for data.
 */
private static BooleanSwitch dataSwitch = 
    new BooleanSwitch("Data", "DataAccess module");

public static void MyMethod(String location)
{
    //Insert code here to handle processing.
    if (dataSwitch.get_Enabled()) {
        Console.WriteLine("Error happened at " + location);
    }
} //MyMethod

public static void main(String[] args)
{
    // Run the method which writes an error message specifying 
    // the location of the error.
    MyMethod("in main");
} //main

// Class level declaration.
 /* Create a BooleanSwitch for data.*/
 static var dataSwitch : BooleanSwitch = new BooleanSwitch("Data", "DataAccess module");
 
 static public function MyMethod(location : String) {
    // Insert code here to handle processing.
    if(dataSwitch.Enabled)
       Console.WriteLine("Error happened at " + location);
 }
 
 public static function Main() {
    // Run the method which writes an error message specifying the location of the error.
    MyMethod("in Main");
 }


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft