Tracing in .NET is another means of debugging, but allows you to insert custom statements added to your page's output, whereby you can "trace" the flow of your code and determine the order of things at run time. Tracing, contrary to debug mode, presents you with a lot of information about your page. It further can help much in ascertaining any performance issues concerning your code. In any event, like debugging, tracing could be implement the same two ways:
- Application wide via the web.config file:
<system.web>
<trace enabled="true"/>
</system.web>
- Or locally within each page's @ Page Directive:
<%@ Page Trace="true" TraceMode="SortByTime | SortByCategory" %>
And within your code you would trace by writing:Trace.Write("Tracing has started")
Trace.Warn("Examine more closely here")
Trace.Write("Tracing has ended")
Trace. Write produces standard output, whereas using Trace.Warn would output your text in red for added notice. And bear in mind that the best place to Trace is usually before and after any major code sections, i.e. Datagrid binding, editing, etc.
With all this error handling now under our belt, what happens now when an error does occur? How do we fix it? Well, next we'll look at some common, though not basic, .NET system errors.
Comments