ThreadAbortException when using Trace

  • Thread starter Christoph Wienands
  • Start date
C

Christoph Wienands

Hey guys,

I just got some really weird behavior. I put the following code into the
Application_Start event in Global.asax:

// init some trace listeners
Uri codeBase = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string fileName = Path.GetDirectoryName(codeBase.LocalPath);
fileName = Path.Combine(fileName, "pmatsiemens_trace" +
DateTime.Now.ToString("yyyyMMddHHmmss") + ".log");
TextWriterTraceListener listener = new TextWriterTraceListener(fileName,
"FileLogger");
Trace.Listeners.Add(listener);
Trace.AutoFlush = true;
Trace.WriteLine("Application started");

When I then run a web application I notice that Application_Start is
executed over and over again. In the output window I see the following error
messages:

Application started
'/LM/W3SVC/1/Root/MyWebApp-34-127730118577453952': Loaded
'c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net
files\mywebapp\2e53becd\66ad82af\qf3dspm5.dll', Symbols loaded.
aspnet_wp!library!af4!10/5/2005-10:51:05:: i INFO: Cleaned 0 batch records,
0 policies, 0 sessions, 0 cache entries, 0 snapshots, 0 chunks, 0 running
jobs
Application ended
An unhandled exception of type 'System.Threading.ThreadAbortException'
occurred in Unknown Module.
Additional information: Thread was being aborted.
The program '[2760] aspnet_wp.exe:
/LM/W3SVC/1/Root/MyWebApp-34-127730118577453952' has exited with code 0
(0x0).
The thread '<No Name>' (0x62c) has exited with code 0 (0x0).

Does anybody have a clue why this is happening?

Thanks, Christoph
 
S

S. Justin Gengo

Christopher,

This is only a guess, but normally in .NET when you change the web.config
file and re-save or change a .dll file and re-save the application restarts
to get the new code. Whatever listner triggers the application restart might
be triggered by your code that is writing to the application's directory.
Try saving elswhere. I think that will resolve the issue.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
B

Brock Allen

The ThreadAbortException is a bit of a trick ASP.NET uses when a Response.Redirect
is used.
 
C

Christoph Wienands

This is only a guess, but normally in .NET when you change the web.config
file and re-save or change a .dll file and re-save the application
restarts to get the new code. Whatever listner triggers the application
restart might be triggered by your code that is writing to the
application's directory. Try saving elswhere. I think that will resolve
the issue.

Goood catch! Should have thought of that myself. Whenever a file changes in
the bin directory the app seems to restart. Now I just save it to a log
directory.

Thanks, Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top