By default, ASP.NET 2.o provides 3 trace listeners:
Trace configuration:
Trace can be controlled using the configuration file. The following configuration has configured an event log trace listener. All the trace information will be routed to event log named EventLogName.
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<remove name="Default"/>
<add name="EventLogListener"
type="System.Diagnostics.EventLogTraceListener,System"
initializeData="MyEventLog"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Trace switch:
Trace switch is used to filter out unwanted trace information. There are 5 levels of trace:
Trace switch configuration:
<system.diagnostics>
<switches>
<add name="MyTraceSwitch" value="3" />
</switches>
<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener" type="CommonLib.TextWriterTraceListener, CommonLib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=92dae50c46d5d3c2" initializeData="c:\temp\CommomLog${0:yyyy-MM-dd}.txt" />
</listeners>
</trace>
</system.diagnostics>
- DefaultTraceListener: Used in Visual Studio Environment
- TextWriterTraceListener: redirect tracing output to an instance of the TextWriter class or to any object that is a Stream class, such as a log file, network stream, or console
- EventLogTraceListener: redirect tracing messages to Windows event log
Trace configuration:
Trace can be controlled using the configuration file. The following configuration has configured an event log trace listener. All the trace information will be routed to event log named EventLogName.
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="2">
<listeners>
<remove name="Default"/>
<add name="EventLogListener"
type="System.Diagnostics.EventLogTraceListener,System"
initializeData="MyEventLog"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Trace switch:
Trace switch is used to filter out unwanted trace information. There are 5 levels of trace:
Off | 0 | Outputs no messages to Trace Listeners |
Error | 1 | Outputs only error messages to Trace Listeners |
Warning | 2 | Outputs error and warning messages to Trace Listeners |
Info | 3 | Outputs informational, warning and error messages to Trace Listeners |
Verbose | 4 | Outputs all messages to Trace Listeners |
Trace switch configuration:
<system.diagnostics>
<switches>
<add name="MyTraceSwitch" value="3" />
</switches>
<trace autoflush="true" indentsize="2">
<listeners>
<add name="myListener" type="CommonLib.TextWriterTraceListener, CommonLib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=92dae50c46d5d3c2" initializeData="c:\temp\CommomLog${0:yyyy-MM-dd}.txt" />
</listeners>
</trace>
</system.diagnostics>
Comments