[VS.Net 2003 .Net 1.1] StreamWriter Exception non gérée !
Bonjour, j'ai un soucis avec un streamwriter qui me sert de fichier de log:
Code:
1 2 3
| if(System.IO.File.Exists(Configuration.racineRepConfig + "log.txt") == false)
{System.IO.File.Create(Configuration.racineRepConfig + "log.txt");}
sw = new System.IO.StreamWriter(Configuration.racineRepConfig + "log.txt",true,System.Text.Encoding.UTF8); |
Ce fichier n'est crée que s'il n'existe pas déjà, et j'ecris dedans de cette facon :
Code:
sw.WriteLine(DateTime.Now + " --> " + MyMessage.Message);
Comme je developpe un serveur, j'aimerai éviter les plantages et malheureusement de temps à autre, il me génére cette exception :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| System.IO.IOException: Le processus ne peut pas accéder au fichier
"D:\pub\wwwroot\dowload-spelog\config\log.txt", car il est en cours
d'utilisation par un autre processus.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath,
Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding
encoding)
at srvimp.form_srvimp.form_srvimp_Load(Object sender, EventArgs e) in
d:\projets\srvimp\srvimp\form1.cs:line 296 |
je finis avec un sw.flush(); sw.close();
Si quelqu'un voit de quoi cela peut venir, je suis preneur. Merci d'avance.
Cordialement.
Niko