What are listeners?

 Posted by Ddd on 3/24/2011 | Category: .NET Framework Interview questions | Views: 3002 | Points: 40
Answer:

These are the classes used to collect the output of Tracing.
The listeners write the Tracing output which they collect to a number of devices.
3 Types of listeners are there:

1)TextWriterTraceListener
It allows us to write messages to an object of the TextWriter class.

2)EventLogTraceListener:
It allows us to write messages to EventLogs

3)DefaultTraceListener:
Allows us to send messages to Output Window.

They are defined by System.Diagnostics namespace

example:
 Stream m = File.Create("dd.txt");


/*Create a TextWriterListener and then add it to the Listeners*/
TextWriterTraceListener t = new
TextWriterTraceListener(m);
Trace.Listeners.Add(t);

// Write output to the file.
Trace.Write("hello ");


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response