473,237 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

System.Diagnostics.Trace in ASP.NET- how not to IISRESET

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.Configu rationSettings.AppSettings["TraceLog"]))
{
myFile =
System.IO.File.Create(System.Configuration.Configu rationSettings.AppSettings["TraceLog"]);
}
else
{
myFile =
System.IO.File.Open(System.Configuration.Configura tionSettings.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(myTextListe ner);
}
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,S ystem, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089,
initializeData=c:\dev\test.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>

Nov 19 '05 #1
1 4265
Hi Welcome to ASPNET newsgroup.

As for the locking file problem you mentioned in ASP.NET web application,
based on my experience, it is likely caused by the FileStream's ShareMode,
when creating such file based log file, we are recommended to create the
FileStream as "ReadWrite" share. For example, when creating the FileStream,
we can use the following code:

FileStream fs = new
FileStream("path",FileMode.OpenOrCreate,FileAccess .ReadWrite,
FileShare.ReadWrite);

Also, I'm not sure why you put the code in SessionStart since session is
per user specific, you should put the application's trace handler
registering code in Application wide event. For example, here is the test
code I used which execute in Application's Start event and I can correctly
read the logfile outside when the application running:

====================
protected void Application_Start(Object sender, EventArgs e)
{
FileStream fs = new
FileStream(Server.MapPath("~/logfiles/traceLog.txt"),FileMode.OpenOrCreate,F
ileAccess.ReadWrite, FileShare.ReadWrite);
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.UTF8);

System.Diagnostics.TextWriterTraceListener txtListener = new
System.Diagnostics.TextWriterTraceListener(sw, "txt_listener");

System.Diagnostics.Trace.Listeners.Add(txtListener );

System.Diagnostics.Trace.AutoFlush = true;
}
====================

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Raj Dhrolia | last post by:
Hi, In one of my method, I want to know the class/function that called/invoked this method. i.e. i have a function named Method1() in class1. I want "ClassX.MethodX()" in Method1(), when...
4
by: A.M | last post by:
Hi, If I use System.Diagnostics.Debug.WriteLine in a asp.net application, where does the output go? Is there any trace monitor application thar shows me the trace output? Thanks, Allan
1
by: Jiho Han | last post by:
I am wondering whether asp.net applications can write trace information using the System.Diagnostics.Trace class, and also whether in web.config, the <system.diagnostics> element and its sub...
4
by: Jiho Han | last post by:
I have the following defined in web.config under <configuration> node: <system.diagnostics> <switches> <add name="MainSwitch" value="4"/> </switches>
2
by: stand__sure | last post by:
Has microsoft changed something here? For some reason calls to System.Diagnostics.Trace get ignored UNLESS I explicitly define TRACE in my application -- this was not how things behaved in VS...
5
by: Ankit Aneja | last post by:
This is my problem. I am using Visual 2003, .Net framework 1.1 and the Application Block I configured the DAAB using the Enterprise Library Configuration now this is the error which is coming ...
1
by: Oleg Ogurok | last post by:
Hi there, My ASP.NET 2.0 app uses an external assembly that calls methods like Trace.Write() and Trace.TraceError() of namespace System.Diagnostics. I need to enable tracing in my web app so...
0
by: msnews.microsoft.com | last post by:
Hi, I am tring to use Trace Listener in asp.net 1.1 application as mentoned here. But i am getting the following error, Configuration Error Description: An error occurred during the processing...
0
by: =?Utf-8?B?QWxleA==?= | last post by:
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...
1
by: samueltilden | last post by:
I am writing one particular web app in ASP.NET 2.0 in debug mode. Even when I step through the code, the IDE skips over every occurrence of System.Diagnostics.Trace.WriteLine(), but honors...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.