CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
This class is an enhanced version of the BooleanSwitch class because it allows us to choose whether to deactivate tracing functionality or display messages using an importance-based hierarchy. The following table lists the levels:
Trace level |
Description |
None: Tracing is deactivated. |
|
TraceError: Only the error messages will be written to the listener application. |
|
TraceWarning: Error and warning messages will be written to the listener application. |
|
TraceInformation: Error, warning, and information messages will be written to the listener application. |
|
TraceVerbose: All kinds of messages will be written to the listener application. |
So, when an error occurs, you can change the application configuration file, specifying to write just the error messages that you have added to the code to focus our attention just on these messages. The configuration file is the same as for the BooleanSwitch example. What changes is the code, as we have to instantiate an object from the TraceSwitch class. Moreover, we will use the enumeration values within the class to specify the level of the tracing messages. Let's see an example, TraceSwitchExample.cs:
using System;We start by declaring a global TraceSwitch object and then create a new object, giving it the name specified in the configuration file. We add a text file log listener to the application. We then start a new thread that contacts the pubs database within SQL Server in order to retrieve all the records from the authors table.
If the thread has been omitted, the Open() method raises an exception that generates a trace error message:
private static void DBThread()Here is the output from the code when the value 1 is specified in the configuration file, which specifies TraceError:
19/04/2002 17:52:23 - Error: ExecuteReader requires an open and available Connection. TheHere is the output when the value 3 is specified in the configuration file, which specifies TraceInformation:
19/04/2002 17:54:23 - EnteredThe Debug class provides the same functionality as the Trace class. You will find that it exposes the same methods and properties, with the same tracing results.
When you change the listener application using the Listeners collection provided by the Trace class, you will change the listener application for Debug messages as well.
The big difference between these two classes is in the context in which you should use them. The Debug class is useful when you need to add information during debugging sessions. Before deploying our application, you will build the release version that will remove debug information from our code, automatically. Therefore, you would add Trace class functionalities when you need to check our application during the run time phase.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 721
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved