P
prowler
Hello,
I'm trying to do something straightforward - trying to
implement trace listeners to pepper my code with traces
triggered by trace switches. I get two problems:
1. The trace.write statements never get written to the
stream (file), it stays 0 bytes. Interestingly,
debug.write statements work.
2. If I use Trace.WriteLine I get a compile error
(intellsense too does not show the method!).
I tried to #define a trace constant at the top of my file,
no effect. Here's my code, any help appreciated...
config file:
<configuration>
<system.diagnostics>
<switches>
<add name="ATraceSwitch"
value="4" />
</switches>
</system.diagnostics>
<system.web>
public class WebForm1 : System.Web.UI.Page
{
static TraceSwitch traceSwitch = new
TraceSwitch("ATraceSwitch", "Demo trace switch");
protected System.Web.UI.WebControls.Label
Label1;
private void Page_Load(object sender,
System.EventArgs e)
{
System.IO.FileStream myTraceLog =
new
System.IO.FileStream
(@"C:\myTraceLog.txt",
System.IO.FileMode.OpenOrCreate);
// Creates the new trace listener.
System.Diagnostics.TextWriterTraceListener
myListener =
new
System.Diagnostics.TextWriterTraceListener(myTraceLog);
System.Diagnostics.Trace.Listeners.Add(myListener);
// traceSwitch.Level =
TraceLevel.Info;
if (traceSwitch.TraceVerbose)
{
Response.Write("verbose");
//Debug.WriteLine("debug
verbose message");
Trace.Write
("traceSwitch.TraceInfo is verbose nabled");
}
if (traceSwitch.TraceInfo)
{
Response.Write("info");
Trace.Write
("traceSwitch.TraceError is info enabled");
}
myListener.Flush();
myTraceLog.Close();
}
I'm trying to do something straightforward - trying to
implement trace listeners to pepper my code with traces
triggered by trace switches. I get two problems:
1. The trace.write statements never get written to the
stream (file), it stays 0 bytes. Interestingly,
debug.write statements work.
2. If I use Trace.WriteLine I get a compile error
(intellsense too does not show the method!).
I tried to #define a trace constant at the top of my file,
no effect. Here's my code, any help appreciated...
config file:
<configuration>
<system.diagnostics>
<switches>
<add name="ATraceSwitch"
value="4" />
</switches>
</system.diagnostics>
<system.web>
public class WebForm1 : System.Web.UI.Page
{
static TraceSwitch traceSwitch = new
TraceSwitch("ATraceSwitch", "Demo trace switch");
protected System.Web.UI.WebControls.Label
Label1;
private void Page_Load(object sender,
System.EventArgs e)
{
System.IO.FileStream myTraceLog =
new
System.IO.FileStream
(@"C:\myTraceLog.txt",
System.IO.FileMode.OpenOrCreate);
// Creates the new trace listener.
System.Diagnostics.TextWriterTraceListener
myListener =
new
System.Diagnostics.TextWriterTraceListener(myTraceLog);
System.Diagnostics.Trace.Listeners.Add(myListener);
// traceSwitch.Level =
TraceLevel.Info;
if (traceSwitch.TraceVerbose)
{
Response.Write("verbose");
//Debug.WriteLine("debug
verbose message");
Trace.Write
("traceSwitch.TraceInfo is verbose nabled");
}
if (traceSwitch.TraceInfo)
{
Response.Write("info");
Trace.Write
("traceSwitch.TraceError is info enabled");
}
myListener.Flush();
myTraceLog.Close();
}