Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-locking TextWriterTraceListener?

Tags:

c#

.net

logging

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?

like image 804
Johannes Rudolph Avatar asked Feb 14 '10 16:02

Johannes Rudolph


2 Answers

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.

like image 113
Hans Passant Avatar answered Nov 09 '22 10:11

Hans Passant


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.

like image 39
Fredrik Mörk Avatar answered Nov 09 '22 11:11

Fredrik Mörk