How to view log output while tests are running in VS 2019 Professional?

AdamLeffert-5988 71 Reputation points
2020-12-28T11:46:27.797+00:00

My goal is to view log output in Visual Studio 2019 Pro, for all unit tests, while the tests are running.

I tried log4net. The log writes to an output file, via log4net.Appender.FileAppender, so I know log4net is configured and running. However, output sent to log4net.Appender.OutputDebugStringAppender and log4net.Appender.ConsoleAppender do not appear in the Visual Studio Output Window, or DebugView++.

I tried writing via Console.WriteLine.

I also tried

Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.AutoFlush = true;

System.Diagnostics.Trace.TraceInformation("hello");

This output appears correctly when I

  • run a test
  • select the test in Test Explorer in VS
  • Click the "Open additional output for this result" link

so I know the code is working.

But I don't want to have to click each test to see the results.

I want to see all the log output, in the Output Window in VS, while the tests are running.

I tried running the tests in both Debug and Release modes.

How to do this?

Thanks!

Adam Leffert
https://www.fullstackdeveloper.com

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
331 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 27,811 Reputation points Microsoft Vendor
    2020-12-29T08:40:42.28+00:00

    Hello @AdamLeffert-5988 ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    I’m afraid, the output information is only displayed in the additional Test Output, instead of displaying in Output Window in VS. So it is not available to see all the log output in the Output Window in VS while the tests are running, and you need to click each test to see the output.

    Besides, if you really want this feature, I recommend you suggest this feature in Developer Community.

    By the way, using log4net, you can try to configure for every test projects and collect the log output from every test projects(test methods) to one specific file, and check all of the log output from that file.

    Sincerely,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. AdamLeffert-5988 71 Reputation points
    2020-12-29T11:13:04.137+00:00

    Thank you for the quick reply. :)

    I will post the request in the Developer Community.

    Yes, log4net works to send all log output to a file.

    For anyone else reading this thread, once the output is being sent to a file, you can run a Windows "tail" utility which displays the contents of the file as they update. Not as convenient as simply having the output in the Output Window, but it works.

    1 person found this answer helpful.
    0 comments No comments

  2. Riz Malabanan 6 Reputation points
    2022-02-19T05:53:27.333+00:00

    TestContext.Progress.WriteLine

    1 person found this answer helpful.

  3. Mahdi Berkia 1 Reputation point
    2021-06-17T23:52:15.393+00:00

    This is probably too late, but TestContext.Progress.WriteLine does exactly what you want.