Hi I am reading the files only but I am getting the error given in Title of this question:
String[] WebServer1 = Directory.GetFiles(System.Configuration.ConfigurationManager.AppSettings["WebServer1"], "webapi_trace*.log");
String[] WebServer2 = Directory.GetFiles(System.Configuration.ConfigurationManager.AppSettings["WebServer2"], "webapi_trace*.log");
var files = WebServer1.Concat(WebServer2);
foreach (var f in files)
{
log = File.ReadAllText(f); //GETTING ERROR HERE
Open in new window
THE ERROR IN DETAIL IS
Timestamp: 1/13/2016 7:25:41 AM
Message: The process cannot access the file 'D:\apps\webapi_trace.log'
because it is being used by another process. at System.IO.__Error.WinIOErr
or(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(
String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor
(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ct
or(String path, Encoding encoding, Boolean detectEncodingFromByteOrde
rMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalRea
dAllText(S
tring path, Encoding encoding, Boolean checkHost)
at log =
File.ReadAllText(f) line 8
Category: Error
Process Name: c:\windows\system32\inetsrv\w3wp.exe
Extended Properties:
HOW CAN I RESOLVE THIS, Does this require a code change.
Our community of experts have been thoroughly vetted for their expertise and industry experience.