G
Guest
When Tracing in ASP.NET, the IIS process (on IIs5.1) is locking on the Trace
file, and I can't read the trace file without restarting the IIS:
Even the following does NOT work (how could I fix this??):
System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToLongTimeString()+
"--" + dirException.ToString());
System.Diagnostics.Trace.Flush();
((System.Diagnostics.TraceListener)
System.Diagnostics.Trace.Listeners[0]).Close();
This is my Session_Start:
protected void Session_Start(Object sender, EventArgs e)
{
// Create a file for output named TestFile.txt.
if (!
System.IO.File.Exists(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"]))
{
myFile =
System.IO.File.Create(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"]);
}
else
{
myFile =
System.IO.File.Open(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"],System.IO.FileMode.Append);
}
/* Create a new text writer using the output stream, and add it to
* the trace listeners. */
System.Diagnostics.TextWriterTraceListener myTextListener = new
System.Diagnostics.TextWriterTraceListener(myFile);
System.Diagnostics.Trace.Listeners.Add(myTextListener);
}
This is my Web.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TraceLog" value="c:\\dev\\test.log" />
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise,
setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that
executes
more slowly, you should set this value to true only when debugging
and to
false at all other times. For more information, refer to the
documentation about
debugging ASP .NET files.
-->
<compilation
defaultLanguage="c#"
debug="true"
/>
<!-- CUSTOM ERROR MESSAGES
Set customError mode values to control the display of user-friendly
error messages to users instead of error details (including a
stack trace):
"On" Always display custom (friendly) messages
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not
running
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote
clients.
-->
<customErrors mode="Off"
/>
<!-- AUTHENTICATION
This section sets the authentication policies of the application.
Possible modes are "Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Windows" />
<identity impersonate="false" />
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page
within an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="true", the
trace information will be displayed at the bottom of each page.
Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your
web application
root.
-->
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong
to a particular session.
If cookies are not available, a session can be tracked by adding a
session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myTextListener"
type="System.Diagnostics.TextWriterTraceListener,System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089,
initializeData=c:\dev\test.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
file, and I can't read the trace file without restarting the IIS:
Even the following does NOT work (how could I fix this??):
System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToLongTimeString()+
"--" + dirException.ToString());
System.Diagnostics.Trace.Flush();
((System.Diagnostics.TraceListener)
System.Diagnostics.Trace.Listeners[0]).Close();
This is my Session_Start:
protected void Session_Start(Object sender, EventArgs e)
{
// Create a file for output named TestFile.txt.
if (!
System.IO.File.Exists(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"]))
{
myFile =
System.IO.File.Create(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"]);
}
else
{
myFile =
System.IO.File.Open(System.Configuration.ConfigurationSettings.AppSettings["TraceLog"],System.IO.FileMode.Append);
}
/* Create a new text writer using the output stream, and add it to
* the trace listeners. */
System.Diagnostics.TextWriterTraceListener myTextListener = new
System.Diagnostics.TextWriterTraceListener(myFile);
System.Diagnostics.Trace.Listeners.Add(myTextListener);
}
This is my Web.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TraceLog" value="c:\\dev\\test.log" />
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise,
setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that
executes
more slowly, you should set this value to true only when debugging
and to
false at all other times. For more information, refer to the
documentation about
debugging ASP .NET files.
-->
<compilation
defaultLanguage="c#"
debug="true"
/>
<!-- CUSTOM ERROR MESSAGES
Set customError mode values to control the display of user-friendly
error messages to users instead of error details (including a
stack trace):
"On" Always display custom (friendly) messages
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not
running
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote
clients.
-->
<customErrors mode="Off"
/>
<!-- AUTHENTICATION
This section sets the authentication policies of the application.
Possible modes are "Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Windows" />
<identity impersonate="false" />
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page
within an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="true", the
trace information will be displayed at the bottom of each page.
Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your
web application
root.
-->
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong
to a particular session.
If cookies are not available, a session can be tracked by adding a
session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="20"
/>
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myTextListener"
type="System.Diagnostics.TextWriterTraceListener,System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089,
initializeData=c:\dev\test.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>