This project is read-only.
1

Resolved

before stop tracing, write remaining trace messages

description

I think that when you stop tracing, it should be better to first write all remaining trace messages to the log file (if the logwriter exists). From what I've seen from testing, this doesn't happen now.

E.g. when I stop tracing to log file, I first trace a message 'tracing disabled', but this never shows in the log file.
(unless I enable file tracing again, but that's not the behaviour I expect).

comments

rekna wrote Dec 15, 2016 at 11:23 PM

The following might solve the problem of writing remaining messages to the log file, when I stop file tracing :

I added the following static method to the Tracer :
public static void FlushTrace()
      {
          tracerTimerMethod(null);
      }
I my own method to stop file tracing I then do the following:
             Tracer.TraceLine("StopFileTracing");
            Tracer.FlushTrace();
            _traceLogFileWriter?.FlushAndCloseLogFileWriter();
            _traceLogFileWriter?.Dispose();
            _traceLogFileWriter = null;
This seems to work, could you verify I this might introduce other issues esp. concerning multithreading?

PeterHuberSg wrote Feb 16 at 10:58 AM

I solved the problem by adding a Flush() method to Tracer. I also added AddMessagesTracedListener() and RemoveMessagesTracedListener() to properly administer event handlers. The parameter needsFlushing is per default true when calling RemoveMessagesTracedListener().

In TraceLogFileWriter I implemented a proper Dispose() and destructor, which will flush Tracer to get all messages.