Pages

Ads 468x60px

Labels

Tuesday, February 5, 2013

Listeners : 4





The settings there noticed that system.diagnostics is a child of the configuration element so I'm output those settings right appear and all same technique can create trace switches in code thereafter all just classes within the.net framework but if you put them within the web.config A lot more flexibility to make changes to them and add new ones without having to compile your code which if set the trace switches then you can create trace listeners in your code to output trace messages the trace listen class defines several objects.

Is an event log trace listener a text writer trace listener Boolean switch and trace which we talked about those the code that implements these is a separate class and so is located within the app code directory although had open up that code file and you can see there's a lot of code in order to implement these listeners first of all the various listeners that I'm using require the system.diagnostics namespace as well as system.

I'll input output in the code defines these listeners I define to trace listeners one an event log trace listener and the other a text writer trace listener and I also define a couple of switches trace switch and Boolean switch the initialize listener class initializes the two trace switches using the names that they were defined with in the web.config file then ASP will be able to look up the activation level of those two switches at runtime so I instantiate a new trace switch object using the name from the web.config and then give it a friendly name is just a demo trace which and I do the same thing for Boolean.

Switch next the code clears the listeners collection you have had other listeners that were enabled browser code or within other configuration files but this starts with a clean slate that creates the two listeners and want to use the event log trace listener it news up that object and gives it friendly text identify and then adds that listener to the collection of listeners that are associated with the trace object in the code creates the trace writer trace listener object but this requires a little bit more work to do first of all we need to get a location for the output for this because it's good to save it to a text file.

Three is the HTTP context object that's available within all ASP.net applications get a reference to the current context and the request object and refer to the physical application path this can return the physical location of the application on the server wait a second what we just use the request object directly or we can't because the current class that this is being used within is not part of a class that inherits from the system.Web.UI.page class to the request object is not automatically available but because this code is executing within a web application we do have access to it through this HTTP context object.

0 comments:

Post a Comment

 

Sample text

Sample Text

Total Pageviews