I'm using TextWriterTraceListener
to ouptput my trace information to a log file. Unfortunately it locks the logfile and I am not able to open it externally while the application is running. Any way to make this possible?
It depends what constructor you used. The TextWriterTraceListener(String) constructor creates a StreamWriter that opens the file with FileShare.Read. That allows any process to read the file.
The usual problem is trying to open the file with the wrong FileShare setting in the other process. You have to specify FileShare.ReadWrite. The trace listener has already gained write access to the file, you cannot deny it.
Whether you can monitor the file externally or not when using TextWriterTraceListener
depends a bit on what software you use for monitoring it. I usually use BareTail that has no issues with the file being locked.
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