0

recently I found our company product (based on .net framework) uses Tracelistenser Class's (under the System.Diagnostics) WriteLine method.

foreach(TraceListener item in traceSource.Listeners)
{
   item.WriteLine($"...");
   item.Flush;
}

Because there is a WriteLineAsync method for the StreamWriter (under the System.IO), I started to think that Tracelistenser's WriteLine method must be a synchronous method. But after searching the source code, I found no clause indicating Tracelistenser's WriteLine is the synchronous method. I just want to know if is there any idea regarding this method?

Besides, the TraceListener inherits MarshalByRefObject,

public abstract class TraceListener : MarshalByRefObject, IDisposable

and the Microsoft doc describes it

as the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy.

Can I consider that this base object could transfer data cross processes? If so, when its derived object TraceListener calls WriteLine, the method is actually writing cross processes, such as writing data into a text note or window's event log?

RicardoMao
  • 95
  • 1
  • 8
  • TraceListener.WriteLine() is *abstract*, so you'll need to do more digging to find out what concrete implementation of TraceListener is getting used in your app. If you can't find any, somewhat likely, then you are using [DefaultTraceListener](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.defaulttracelistener?view=net-7.0). Output goes to the VS Output window and asserts produce a message box. And it is not async, output is buffered by the OS. – Hans Passant Jul 10 '23 at 15:32

0 Answers0