Search code examples
c#loggingvisual-studio-debugging

How is Visual Studio or Rider reading messages written using System.Diagnostics.Trace.Write?


My understanding is that you need to register a listener to the trace output, but how would that even look like? Is there a trace stream associated with each execution of the application that Visual Studio/Rider listens to?

We can rephrase this question by asking:
How to write a simple console app that executes another application and listen to its trace output.


Solution

  • To receive another application's debugging output, you need to attach to it as a debugger and call the WaitForDebugEvent function, looking for OUTPUT_DEBUG_STRING_INFO results (dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)

    If the other application is .NET, you potentially have some easier options, including configuring additional trace listeners in the app.config.