Logging on BeginRequest but file used by another process

F

Frank

Hi,

I'm logging requests by opening the log file on each
Application_BeginRequest event with:
StreamWriter log = File.AppendText(logFilename);

This works most of the time but sometimes I get an IOException with the
message:
The process cannot access the file <filename> because it is being used by
another process.

Can this be caused by requests that occurr at the same time? (Threading)
Or if its another process (e.g. Virus scanner) should I keep the file open?
Make StreamWriter log static?

Any ideas on how to prevent this.
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top