mercredi 29 avril 2015

System.IO.IOException: The process cannot access the file '.txt' because it is being used by another process

I am using the next code to log errors of an web application.

using (StreamWriter myStream = new StreamWriter(sLogFilePath, true))
{                
myStream.WriteLine(string.Format("{0, -45}{1, -25}{2, -10 {3}", guid, DateTime.Now, StringEnum.GetStringValue(enumMsg), sText));      

}

Sometimes, the following exception 'System.IO.IOException: The process cannot access the file '.txt' because it is being used by another process.' is thrown.

I think this is caused by multiple instances of the web app at the same time. Can you help me fix this problem, please ?

EDIT: I have to add that for every method I log like this:

Date - Method X started.

Date - Exception.Message (table not found or other errors)

Date - Method X stopped.

and when this Error appears, it's logged only this:

Date - System.IO.IOException: The process cannot access the file '.txt' because it is being used by another process.

Aucun commentaire:

Enregistrer un commentaire