C
C#2w ago
Erky

How to overwrite a file that is used by another process?

I know which process is locking it, its a .net host instance, but I still want to overwrite my .log file (i want to clear it, when i press a button). I keep getting System.IO.IOException: The process cannot access the file
9 Replies
ACiDCA7
ACiDCA72w ago
-wait till you CAN access -kill the process else out of luck
Erky
ErkyOP2w ago
im looking for a way to force it
mtreit
mtreit2w ago
You can't.
Erky
ErkyOP2w ago
I googled "log4net reset logs file" did show some interesting results, i will continue there if you cant help
ACiDCA7
ACiDCA72w ago
well there are a couple of tools which help you force free filehandles(sysinternals provides something).. but you should just fix your code..
Sehra
Sehra2w ago
this will surely end well
jcotton42
jcotton422w ago
@Erky all the ways you could force this would probably crash (or at least cause an exception in) the writing process.
Erky
ErkyOP2w ago
maybe forcing it is the wrong idea, but rather just investigating nuget package, log4net, client.log and edit configuration or something
wasabi
wasabi2w ago
In Unix yes, in Windows no. Heh.

Did you find this page helpful?