What are trace switches?

 Posted by ArticlesMaint on 9/16/2009 | Category: ASP.NET Interview questions | Views: 3814

Answer: -
Trace switches helps us to control and govern the tracing behavior of a project. There are two types of trace switches ‘BooleanSwitch’ and ‘TraceSwitch’. BooleanSwitch, as the name says, is a kind of on/off switch which can be either enabled (true) or disabled (false).

‘TraceSwitch’ on the other hand offers more options rather than simple true/false like ‘BooleanSwitch’. Tracing is enabled for a TraceSwitch object using the Level property. When we set the Level property of a switch to a particular level, it includes all levels from the indicated level down. For example, if you set a TraceSwitch's Level property to TraceLevel.Info, then all the lower levels, from TraceLevel.Error to TraceLevel.Warning, will be taken in to account. Below are the various levels in ‘TraceSwitch’ object.
Off a Outputs no messages to Trace Listeners
Error a Outputs only error messages to Trace Listeners
Warning a Outputs error and warning messages to Trace Listeners
Info a Outputs informational, warning and error messages to Trace Listeners
Verbose a Outputs all messages to Trace Listeners

TraceSwitch objSwitch = new TraceSwitch("TraceWarningandError", "Error in trace") ;
objSwitch.Level = TraceLevel.Warning ;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response