I would like to get all the logs files of my iis server and then send the content to a database.
This is my code:
string[] filePaths = Directory.GetFiles(@"C:\inetpub\logs\LogFiles\W3SVC1", "*.log",
SearchOption.AllDirectories);
foreach (var file in filePaths)
{
var lines = File.ReadAllLines(file);//exception
foreach (var line in lines)
{
client.Send(line);
}
}
The problem is that I am getting an exception when I try to read the files of the folder:
IOException was unhandled
The process cannot access the file 'C:\inetpub\logs\LogFiles\W3SVC1\u_ex140625.log' because it is being used by another process.
I understand the reason, but I cannot see which process is locking the file except the iis server itself but I cannot stop it, so how can I access to these logs files?