microsoft / testfx

MSTest framework and adapter
MIT License
750 stars 255 forks source link

Can't get TraceSource output to log in test report #1111

Closed bkqc closed 2 years ago

bkqc commented 2 years ago

Description

I have a project in which I have tracing to TraceSources. I would like to have the output of it logged in the test explorer report window.

Steps to reproduce

Create a SUT in which you do something like

var sourceTrace = new TraceSource("MyTracer");
sourceTrace.Switch.Level = SourceLevels.Information;
sourceTrace.TraceInformation("My trace text");

Expected behavior

In the Test Explorer window, for the tests that executed, even for DataTests, get "My trace text" in the test report.

Actual behavior

Environment

Windows 10 VS 2019 (16.11.10) FW 4.8.04084 MSTest.TestAdapter 2.2.8 MSTest.TestFramework 2.2.8

bkqc commented 2 years ago

This post explains the reason why ConsoleTraceListener in the app.config does not work natively but the custom filewriter listener does. https://stackoverflow.com/questions/71758259/trace-to-mstest-v2-test-log-using-tracesource/72324658