23 August, 2011

Enable Tracing in .net IDE

This is build in service provided by asp.net to map the status of your website.you can use it for debugging purpose. for ex. you can watch all incoming request to your webpage,its status code,rest headers, etc...

There is no extra tool is requred.

you can easily enable it and disable it without editing individual pages. When your application is complete, you can turn off tracing for all pages at once.

2 ways to enable trace 
  1.  page level :   just add "trace" attribute to "true" at @page directive.
  2. Application level : make some setting in web.config as given below.
Example of page level tracing :

<%@ Page language="c#" Trace="true" %>

this will enable tracing option only to particular page.so when you will run this page you can see o/p like image given below after your page information :




 Example of Application level Tracing :

You can enable tracing for an entire application in the Web.config file in the application's root directory. By default, application-level tracing can be viewed only on the local Web server computer. You must set the localOnly attribute to false in the Web.config file to make application-level trace information visible from remote computers.

CAUTION To help keep your Web application secure, use the remote trace capability only when you are developing or deploying your application. Be sure to disable it before you transfer your application onto production Web servers. To disable remote tracing, set the localOnly attribute to true in the Web.config file.

The following example shows an application trace configuration that collects trace information for up to 40 requests and allows browsers on computers other than the origin server to display the trace viewer.

  
     
 

When you enable tracing for an application, ASP.NET collects trace information for each request to the application, up to the maximum number of requests you specify. The default number of requests is 10. When the trace viewer reaches its request limit, the application stops storing trace requests.

Note When you enable tracing for an entire application in the Web.config file, trace information is gathered and processed for each page in that application. To disable tracing for a particular page in the application, set the Trace attribute in that page's @ Page directive to false. Any TraceContext.Write or TraceContext.Warn statements that you include in a page's code are stored and returned to the trace viewer only.

If you want trace information to appear at the end of the page that it is associated with, set the pageOutput attribute in the tracing configuration section of the Web.config file to true. If you want tracing information to be displayed only in the trace viewer, set this attribute to false. If you enable application-level tracing, but you do not want trace information displayed for some pages of the application, use the @ Page directive to set the Trace attribute to false for those pages you do not want trace information displayed in.

Output :


-------------------------------------------------------------------------------------------------------

How to: View ASP.NET Trace Information with the Trace Viewer ?

To view trace details for a specific request

  1. Navigate to Trace.axd in the root of your application.
    For example, if the URL for your application is http://localhost/SampleApplication, navigate to http://localhost/SampleApplication/trace.axd to view the trace information for that application.
  2. Select the View Details link for the request that you want to investigate.

To clear requests from the trace viewer

  1. Navigate to Trace.axd in the root of your application.
  2. Select the clear current trace link to remove all the requests stored in the trace viewer.







No comments:

Post a Comment