Friday, October 14, 2011

ASP.NET interview questions: - Can you explain the concept of trace listener?

‘Tracelistener’ are objects that get tracing information from the trace class
and they output the data to some medium. For instance you can see from the
figure ‘TraceListener’ how it listens to the trace object and outputs the same
to UI, File or a windows event log. There are three different types of
‘tracelistener’ first is the ‘defaulttracelistener’ (this outputs the data to
UI), second is ‘textwritertracelistener’ (this outputs to a file) and the final
one is ‘Eventlogtracelistener’ which outputs the same to a windows event log.

Figure: -Trace listeners

Below is a snap shot for ‘textwritertracelistener’ and ‘eventlogtracelistener’. Using ‘textwritertracelistener’ we have forwarded the trace’s to ‘ErrorLog.txt’ file and in the second snippet we have used the ‘Eventlogtracelistener’ to forward the trace’s to windows event log.

Figure: - Tracelistener in action

See the following video on Web.config transformation as follows: -

See ASP.NET interview questions for interview preparation

View more author’s blog on ASP.NET interview questions

No comments: