How to prevent VS2022 from swallowing Trace output when debugger is attached?

145 Views Asked by At

I'm running a .NET 7.0 project from VS2022 and I'd like to simply output all Trace messages to DebugView++. Everything works great, but only when there is no debugger attached. If I start debugging the project in VS, Trace.Write() goes only to the Output window. If I detach the debugger, DebugView++ will immediately begin showing the Trace messages. If I reattach the debugger, it will immediately stop writing to DebugTrace and writes in the Output window. I can switch it all day long, so it seems the Output window is redirecting all Trace output to the Output window; all I want is for VS to stop screwing with the Trace output always and forever. Is this even possible?

    public static class Logger
    {
        readonly static TraceListener? listener = null;

        static Logging()
        {
            Trace.Listeners.Clear();

            listener = new DefaultTraceListener();
            Trace.Listeners.Add(listener);

            Trace.AutoFlush = true;
        }

        public static void Trace(string message, [CallerMemberName] string callerName = "")
        {
            var msg = $"[TestProject|{callerName}] {message}";

            System.Diagnostics.Trace.WriteLine(msg);
        }
    }
0

There are 0 best solutions below