Hi.
Does anybody know if System.Diagnostics.TraceSource is supported under
ASP.NET? I've used this class along with SourceSwitch and
TextWriterTraceListener in Windows apps but this is the first time I attempt
it in a web app. Specifically, does anyone know why the code below works in a
Windows application but not under an ASP.NET application?
What's interesting (frustrating I should say, since I don't understand the
behavior) is that in the web app, the last 2 lines do get executed if you
step through the code. Line oTSource.TraceData (3rd from the bottom) however,
is totally bypassed. In addition if you perform a Rename on the oTSource
object, all of the instances in the code change except again for the line 3rd
from the bottom. So somehow it is clear ASP.NET is not recognizing this line
but I have no idea why.
' set up the trace objects
Dim oTSource As New System.Diagnostics.TraceSource("TSource")
Dim oTSwitch As New System.Diagnostics.SourceSwitch("TSwitch", "Information")
Dim oTListener As New
System.Diagnostics.TextWriterTraceListener("C:\App Log.txt", "TListener")
' assign the switch to the trace source object
oTSource.Switch = oTSwitch
' add the listener to the listeners collection of trace source object
oTSource.Listeners.Add(oTListener)
' remove the default listener
oTSource.Listeners.Remove("Default")
' log a message to the C:\AppLog.txt file. File permissions have to allow
for this.
oTSource.TraceData(Diagnostics.TraceEventType.Info rmation, 1, "Tracing
message")
' flush the trace source to force writing to the file.
oTSource.Flush()
' close it
oTSource.Close()
Regards,
-Alex