Debug.WriteLine not working

前端 未结 13 1854
梦毁少年i
梦毁少年i 2020-12-03 03:07

In the past, perhaps versions of Visual Studio prior to the 2008 that I am using now, I would do something like this in my VB.NET code:

System.Diagnostics.De         


        
相关标签:
13条回答
  • 2020-12-03 03:22

    Some extra ideas to try or check:

    • Put a breakpoint before Debug.WriteLine and see what's in System.Diagnostics.Trace.Listeners collection. You should see DefaultTraceListener. If you don't see anything, then no one is listening and that's problem.
    • Is it possible that the trace listeners being cleared/modified somewhere such as in config file or in the code?
    • Have you installed any package or add-in to Visual Studio? or using a third-party library?
    • Can you see debug messages outside of VS? There is a SysInternals application called DebugView that monitors and shows debug output in your system. Run that tool and then run your application. You should see your debug message in DebugView. At least you will know that your application is outputting debug messages but VS does not seem to be listening.
    • Have you gone through the contents of the output window to see if there is any exception or error being reported. Your debug output is not there but there might be somethings in there that can provide some clues.
    0 讨论(0)
  • 2020-12-03 03:24

    I had a similar issue with Visual Studio 2013 and MS unit testing. Right clicking on a unit test method and selecting Run Tests any Debug.WriteLine calls would not show up in either the immediate window or the debug output window. Even though the library I was testing and the unit test project itself both had DEBUG conditional checked in the build section of there project properties.

    In order for the Debug.WriteLine statements to output anything I needed to run the unit tests by right clicking and selecting Debug Tests. Only then did I get the debug output being written to the debug output window.

    0 讨论(0)
  • 2020-12-03 03:28

    Make sure you press F5 to Start Debugging mode (not Ctr+F5).

    F5 Starting Debugging

    CTRL+F5 Starting Without Debugging

    0 讨论(0)
  • 2020-12-03 03:29

    I was having the same problem for an ASP.NET application, and I found out that my Web.Config had the following line:

    <system.web>
        <trace enabled="false"/>
    </system.web>
    

    Just changing it to true, and I started seeing the Debug.WriteLine in Output window.

    0 讨论(0)
  • 2020-12-03 03:31

    Check to see if the "Redirect all Output Window text to the Immediate Window" is checked under Tools -> Options -> Debugging -> General.

    Alternatively, you can use the Console.WriteLine() function as well.

    0 讨论(0)
  • 2020-12-03 03:32

    For me this was the fact that Debug.WriteLine shows in the Immediate window, not the Output. My installation of Visual Studio 2013 by default doesn't even show an option to open the Immediate window, so you have to do the following:

    Select Tools → Customize 
    Commands Tab
    View | Other Windows menu bar dropdown
    Add Command...
    The Immediate option is in the Debug section.
    

    Once you have Ok'd that, you can go to menu ViewOther Windows and select the Immediate Window and hey presto all of the debug output can be seen.

    Unfortunately for me it also showed about 50 errors that I wasn't aware of in my project... maybe I'll just turn it off again :-)

    0 讨论(0)
提交回复
热议问题