We flush the
listeners buffer that just clears all the messages and put them where they need
to be the last step is to display that message on the page and then do a
cleanup that just ties up all the loose ends of the listeners now access the
application first welcome back of the web.config make sure that I have my
switches set and I do Boolean switch is set to once.
It's true and the
multi-switch is set to four which is going to be verbose just means of this
good output all the messages I'll go and run the application and I'll click on
the trace which is an trace listeners like there scroll down a bit here and you
can see that we have some output text based on the settings of the switches and
the information that we generated within the page obviously probably not going
to add this kind of information to the page but you could but you could also do
other things conditionally.
Based on the switch settings that you specify within
web.config elbow back over to Visual Studio else like the tracing project will
go ahead and stop the application to refresh the list of files and we can see
that we have a new file here called trace log.txt I can open that up and you
can see that we have that output which was sent to the text writer listener
similarly you can go into the Windows event log and see that there are messages
that are stored there because we used an event log listener right let's go back
over the web.config.
And let's set the Boolean switch to zero and let's set this
switch to one and I'll go ahead and run the application again will select default.aspx
and that's the start of page and click on the link and I can see the results
are different in the page on the back of the Visual Studio it tells me the
trace log.txt changed Saul reload that and take a look at it and now has
different contents based on the conditions of the switches that are set within
web.config that even though most of the messages were written using only the
pages trace.write method and didn't use the system.diagnostics.trace object all
the messages were routed to the listeners because the web.config file set.
The
right to diagnostics trace option to true there's another trace listener that
is a part of system.diagnostics the system.Web namespace includes a trace
listener drive type called webpage trace listener what it does is it serves as
a counterpart to the right to diagnostics trace what this means is that the
webpage trace listener what you go the other way and monitor components that
use the system.diagnostics classes for tracing and captures the
system.diagnostics.trace messages in ASP.net page traces when you add an
instance of the webpage trace listener is added to the trace listeners
collection and messages written to the.net diagnostics trace.
0 comments:
Post a Comment