Because you intend to use a business component in web and non-web applications, you want to enable tracing within the component without having to reference its current HTTP context.
Modify web.config, as shown in Example 13-12, to add the
WebPageTraceListener listener to the
Listeners collection and make it available to your application.
In your non-web-specific components, add plain-vanilla
Trace.Write statements to output any desired information to the trace log, as shown in our sample component in Examples 13-13 (VB) and 13-14 (C#).
The .NET Framework uses the concept of trace listeners in its handling of trace messages. By default, the
TraceListeners collection contains a single listener (
DefaultTraceListener) when you enable tracing. Additional listeners can be added via the web.config file or programmatically. When a
Trace.Write is executed, all listeners in the
TraceListeners collection receive and process the message. This mechanism allows you to add trace statements to your components without the need to add a reference to the
ASP.NET 1.x does not provide any functionality to write trace information within your application’s business and data tiers and display it in the page trace data. If you need this functionality ...