There are many explanations out there how to empty a log file.
Like:
File.WriteAllText(activeTab.FileName, string.Empty);
But this example and other examples I found all have the same problem. It do not work if the logfile is currently locked by another process.
In ruby there is a task I can use rake log:clear
which do not remove, just empty the log files.
I found also that I can this with Powershell using clc <filename>
.
The sources are available here now:
But honestly I do not understand how this code works, also it inherits from other classes.
Is there a C# implementation available that I can use in any common program/class?
Turns out that the file can be cleared in my case using this snippet:
var stream = new FileStream(FileName, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete);
stream.Close();