CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
Using this class in the traced code, you can decide to activate/deactivate messages by simply changing a value in the application configuration file. The WriteLineIf( and WriteIf() methods will be useful to write messages depending on the Enabled property provided by the BooleanSwitch class. In order to add switches to your application you have to follow these few steps:
Add an application configuration file either manually, or by selecting Add New Item from the Project menu within Visual Studio .NET, and choosing the Text File template from the dialog box choosing the App.config filename.
Open the configuration file in order to insert the necessary XML tags to inform the application about the switch name and value. Specifying a value equal to 0 will deactivate tracing functionality, and a value of activate it:
<?xml version='1.0' encoding='utf-8' ?>
<configuration>
<system.diagnostics>
<switches>
<add name='MySwitch' value='1' />
</switches>
</system.diagnostics>
</configuration>
Create a new BooleanSwitch object in the code that has the same name as that specified in the configuration file. You could also use the Enabled property in conjunction with the Trace static methods. Let's continue our Debugging example, by declaring a global BooleanSwitch object in order to use it everywhere in the code:
BooleanSwitch bs;
static void
In
the
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 637
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved