I'm trying to read a log file of log4net:
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)
and I get the Exception specified on the topic. I guess log4Net is holdin an exclusive lock on the file, but, as for example Notepad++ can read the file, I guess is technically possible to do this.
Any help?
Windows Update Code 0x80070020 The existing process cannot access the file because it is being used by another process. To fix this error, you will need to use the MSCONFIG tool to get the PC into a clean boot state and then try to update it again.
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) //...
http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx
Your log may be write locked, so try with FileShare.ReadWrite.
Try to add the FileShare option, see if that helps:
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
EDIT: corrected code, not FileShare.Read
but FileShare.ReadWrite
does the trick (as Guillaume showed as well). The reason: you want to open your file and allow others to read and write it at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With