bramkiPrzeczytaj plik dziennika jest używany przez inny proces
chcę nacisnąć przycisk na moim GUI i czytać w pliku dziennika seclog.log (Symantec AV) z komputera zdalnego i wyświetlania zawartości katalogu zaloguj się do pola tekstowego w mojej aplikacji.
rzeczy, które działają
wszystko ale czyta plik dziennika
Komunikat o błędzie
System.IO.IOException was unhandled
Message=The process cannot access the file '\\HOSTNAME\C$\Program Files (x86)\Symantec\Symantec Endpoint Protection\seclog.log' because it is being used by another process.
Source=mscorlib
kod
//possible seclog paths
String seclogPath1 = @"\\\\" + target + "\\C$\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\seclog.log";
String seclogPath2 = @"\\\\" + target + "\\C$\\Program Files\\Symantec\\Symantec Endpoint Protection\\seclog.log";
//if seclog exists
if (File.Exists(seclogPath1))
{
//output.AppendText("file exists at " + seclogPath1);
//var seclogContent = File.Open(seclogPath1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Stream stream = File.OpenRead(seclogPath1);
StreamReader streamReader = new StreamReader(stream);
string str = streamReader.ReadToEnd();
output.AppendText(str);
streamReader.Close();
stream.Close();
}
miejsca Próbowałem
File is being used by another process
C# The process cannot access the file ''' because it is being used by another process
Googling problem
korzystając filestreams na wiele sposobów
Nicea, że znalazł rozwiązanie. Chciałam podać link do posta z tym samym numerem: http: //stackoverflow.com/questions/3560651/whats-the-least-invasive-way-to-read-a-locked-file-in- c-sharp-maybe-in-unsaf – joshgo
@joshgo thanks! Wpatrywałem się w kod i na godzinę, zanim to rozgryzłem. lol – toosweetnitemare
To rozwiązanie sprawdziło się przy implementacji Serilog. W podobnej sytuacji musieliśmy przeczytać część pliku dziennika, aby przedstawić ją w interfejsie internetowym, ale odczyt nie powiódł się, to rozwiązało. –