Exforsys

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor

Ads


Home arrow Technical Training arrow VB.NET 2005

Web Application Tracing and Debugging Page - 2

Page 2 of 3
Author : Exforsys Inc.     Published on: 30th Jul 2005    |   Last Updated on: 24th Dec 2007

Web Application Tracing and Debugging


.
.

.

.
.
.

Ads

Trace Listeners

While using Trace and Debug, it is important to set up a mechanism for collecting and recording the messages that are sent. Trace messages are received by listeners. The purpose of a listener is to collect, store and route tracing messages. Listeners direct the tracing output to a designated target such as a log or a window or a text file.

Three types of predefined listeners are available:

1. A TextWriterTraceListener that redirects the outpur to an instance of TextWriter or to a stream class.

2. An EventLogTraceListener which redirects the output to an event log

3. A DefaultTraceListener which gives out Write and WriteLine messages to the OutputDebugString and to the Debugger.log method.

If the user wants any listener besides the DefaultTraceListener to receive Debug and Trace output, he must add it to the Listeners collection. Examine the following lines of code:

System.Diagnostics.Trace.WriteLine("Error in Widget 42")
System.Diagnostics.Trace.Listeners.Clear()
System.Diagnostics.Trace.Listeners.Add(New System.Diagnostics.TextWriterTraceListener(Console.Out))
If Not Request.Cookies("username")
Is Nothing Then

The first part is used to add a listener object to a Trace.Listeners collection in the application. The second part is used to make the listener to send tracing information t a console.

Trace Switches

Trace switches helps enable, disable and filter tracing output. These objects are existing in the code and also can be configured externally through the .config file. The .NET infrastructure provides two types of switches namely, BooleanSwitch class and TraceSwitch Class. The BooleanSwitch acts as a toggle switch, either enabling or disabling a variety of trace statements and the TraceSwitch Class allows you to enable a trace switch for a particular tracing level so that the trace message specified for that level and all the levels below it appear. If this switch is disabled, the trace messages will not appear.

Trace switches are useful in filtering information. For instance is the user wants only error messages in the application displayed. By using the .config file to configured with the appropriate settings we can control the types of messages that are received.

The developer needs to create a switch object from a BooleanSwitch class or TraceSwitch Class or he may use a developer defined switch.

A TraceSwitch object has four properties that return Boolean values indicating whether the switch is set at a particular level as given below:

1. TraceSwitch.TraceError Property
2. TraceSwitch.TraceWarning Property
3. TraceSwitch.TraceInfo Property
4. TraceSwitch.TraceVerbose Property

The appropriate levels can be set as per need using the properties as under:

Enumerated value

Integer value

Type of message displayed
(or written to a specified output target)

Off

0

None

Error

1

Only error messages

Warning

2

Warning messages and error messages

Info

3

Informational messages, warning messages, and error messages

Verbose

4

Verbose messages, informational messages, warning messages, and error messages

The following lines of code are used to create a switch object and use it to filter trace output:

Dim myTraceSwitch As New System.Diagnostics.TraceSwitch("SwitchOne", "The first switch")myTraceSwitch.Level = System.Diagnostics.TraceLevel.Error
' This message box displays true, becuase setting the level to
' TraceLevel.Info sets all lower levels to true as well.
MessageBox.show(myTraceSwitch.TraceWarning.ToString())
' This messagebox displays false.
MessageBox.Show(myTraceSwitch.TraceVerbose.ToString())

Conditional Compilation

While developing applications in .NET, the user can select any specific sections of the code to compile while excluding the other sections. Conditional compilation statements are designed to run during compile time and not at run time.

#Const directive is used to declare a conditional compiler constant. The user can typically assign any particular block of code to be compiled by using #IF … Then #Else directive. Let us assume that we are writing debugging statements that check the performance of order processing in a eCommerce solution and is to be used to process data of multiple types of customers who pay using credit card, direct account debit and by cheque. The Conditional compiler code will be like the following:

#If CreditCard Then
…..the code for credit card holders
#Elseif AccoutDebit Then
….the code for AccountDebit
#Else
….the code for other options
#End If

The value of the Credit Card can set a constant to true at compile time to compile the code written for that.

The predefined constants available for conditional compilation are given below:

Constant

Description

CONFIG

A string that corresponds to the current setting of the Active Solution Configuration box in the Configuration Manager.

DEBUG

A Boolean value that can be set in the Project Properties dialog box.

TARGET

A string representing the output type for the project or the setting of the command-line /target option. The possible values of TARGET are: "winexe" for a Windows application, "exe" for a console application, "library" for a class library, and "module" for a module. The /target option may be set in the Visual Studio integrated development environment

TRACE

A Boolean value that can be set in the Project Properties dialog box. By default, all configurations for a project define TRACE.

VBC_VER

A number representing the Visual Basic version, in major.minor format. The version number for Visual Basic




 
This tutorial is part of a VB.NET 2005 tutorial series. Read it from the beginning and learn yourself.

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor
 

Comments