dotnetcore using TraceListener -- need to flush and close then reopen and append

146 Views Asked by At

I'm writing Trace output to a file, but I can't leave it open because the system never hits a point where I am sure everything is finished; i.e., it hangs.

I don't want to keep opening new files with every TRACE. Can't I reopen the TraceListener so I can append to the file?

Much appreciated. Chuck

1

There are 1 best solutions below

0
Yogi Bear On

ANSWER: it turns out that Tracing can be done easier than I thought. I wrote a little C# application so I could try every combination of uses. Once you open the listener in the application, you can write to it at will. Flushing empties buffers (in my case I write to a file) and the output all goes into the file.
Now you can CLOSE the file and at that point you can either OPEN it again to the same place with the same name etc (WITHOUT losing anything in the file) or you can just go ahead the write to it. Again, you can flush if you like and it is all appended to the file. OR you can Close again and it is appended to the file (Closing automatically does a flush).
It certainly answers all my questions. I hope it does yours as well.