473,737 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Diagnost ics.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.Diagnost ics.Trace.Write Line(System.Dat eTime.Now.ToLon gTimeString()+
"--" + dirException.To String());
System.Diagnost ics.Trace.Flush ();
((System.Diagno stics.TraceList ener)
System.Diagnost ics.Trace.Liste ners[0]).Close();
This is my Session_Start:
protected void Session_Start(O bject sender, EventArgs e)

// Create a file for output named TestFile.txt.
if (!
System.IO.File. Exists(System.C onfiguration.Co nfigurationSett ings.AppSetting s["TraceLog"]))
myFile =
System.IO.File. Create(System.C onfiguration.Co nfigurationSett ings.AppSetting s["TraceLog"]);
myFile =
System.IO.File. Open(System.Con figuration.Conf igurationSettin gs.AppSettings["TraceLog"],System.IO.File Mode.Append);

/* Create a new text writer using the output stream, and add it to
* the trace listeners. */
System.Diagnost ics.TextWriterT raceListener myTextListener = new
System.Diagnost ics.TextWriterT raceListener(my File);
System.Diagnost ics.Trace.Liste ners.Add(myText Listener);
This is my Web.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<add key="TraceLog" value="c:\\dev\ \test.log" />


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
into the compiled page. Because this creates a larger file that
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.
defaultLanguage ="c#"
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
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote
<customErrors mode="Off"

This section sets the authentication policies of the application.
Possible modes are "Windows", "Forms",
"Passport" and "None"
<authenticati on mode="Windows" />

<identity impersonate="fa lse" />

Application-level tracing enables trace log output for every page
within an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="tru e", 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
requestLimit="1 0"
pageOutput="fal se"
traceMode="Sort ByTime"
localOnly="true "

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="tru e".
stateConnection String="tcpip=1"
sqlConnectionSt ring="data source=127.0.0. 1;user id=sa;password= "
cookieless="fal se"

This section sets the globalization settings of the application.
<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8"

<system.diagnos tics>
<trace autoflush="true " indentsize="4">
<add name="myTextLis tener"
type="System.Di agnostics.TextW riterTraceListe ner,System, Version=1.0.500 0.0,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9,
initializeData= c:\dev\test.log "/>
</system.diagnost ics>

Nov 19 '05 #1
1 4369
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("pat h",FileMode.Ope nOrCreate,FileA ccess.ReadWrite ,
FileShare.ReadW rite);

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_Sta rt(Object sender, EventArgs e)
FileStream fs = new
FileStream(Serv er.MapPath("~/logfiles/traceLog.txt"), FileMode.OpenOr Create,F
ileAccess.ReadW rite, FileShare.ReadW rite);
StreamWriter sw = new StreamWriter(fs ,System.Text.En coding.UTF8);

System.Diagnost ics.TextWriterT raceListener txtListener = new
System.Diagnost ics.TextWriterT raceListener(sw , "txt_listener") ;

System.Diagnost ics.Trace.Liste ners.Add(txtLis tener);

System.Diagnost ics.Trace.AutoF lush = 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

Nov 19 '05 #2

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

Similar topics

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 MethodX() of ClassX invokes Method1() function I think System.Reflection might provide some help. Regards.
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
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 elements have effect. Trace.axd is good but not perfect. I would like to use a separate file for writing trace information in addition to Trace.axd. Also, what happens when you call Trace.Close which has a set of listeners including a text file...
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>
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 2003. Have they changed this or do I have problems with my VS 2005 beta version?
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 Security Exception Description: The application attempted to perform an operation not allowed
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 that I could see the trace messages from the component. Here's what I've added to web.config so far: <system.web>
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 of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Exception in configuration section handler.
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 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...
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 System.Diagnostics.Debug.WriteLine(). I have other web app's that run fine, Trace.WriteLine() actually writes to the output window and my TraceListener catches it. What can I configure / set so that this web app honors
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.