none
Having problem with limiting size of TRX file on test runs RRS feed

  • Question

  • My C# automated tests do a lot of logging with System.Diagnostics.Trace.WriteLine method.  I am using this method because it logs information to the output window when I am debugging tests with Visual Studio.  it is also writing log entries to the TRX file.  The problem I am facing is when I run these tests using TFS 2015, I get an OutOfMemoryException because the TRX file has too much data in it.  I have read a few articles that seem to indicate the TRX file has a limited size.

    Is there any way I can disable or limit the amount of log data from Trace.WriteLine that goes into the TRX file to prevent this OutOfMemoryException from occurring?  I thought that maybe I could use System.Diagnostics.Debug.WriteLine, but I think that also goes to the TRX file.  I used to use Console.WriteLine, but later versions of Visual Studio (2017+) no longer write Console to the Output window.  Not sure what my options are at this point.

    Monday, July 15, 2019 3:24 PM

Answers

  • Dylan,

    Yes, my solution did work.  When using the System.Diagnostics.Debug command, the string is only written to the Output window when compiling with Debug configuration.  

    I already write log output to a file.  My original goal was to be able to see the log lines in the Output window when debugging tests locally, and not have the Output go into the TRX file when running the tests in TFS.  Using the Release configuration for the build when running in TFS disables the System.Diagnostics.Debug  logging, which then cuts down the amount of data written to the TRX file, thus preventing OutOfMemoryException from occurring.

    • Marked as answer by Ken Varn Friday, July 19, 2019 12:40 PM
    Friday, July 19, 2019 12:40 PM

All replies

  • Hi Ken Varn,

    Welcome to MSDN forum.

    According to your descrition, I am afraid that there is an appropriate method the modify data which is from trx file.

    And I have a try the below code, they all would be displayed in the output window and written to trx file.

            public void TestMethod1()
            {
                Console.WriteLine("1113123123");
    
                TestContext.WriteLine("test context");
            }
    
            public TestContext TestContext
            {
                get { return testContextInstance; }
                set { testContextInstance = value; }
            }
    
            private TestContext testContextInstance;

    So if possible, we suggest you could split your test case to smaller size.

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, July 16, 2019 9:40 AM
  • The Test Cases are already split into small methods.  The problem is more in relation to the accumulation of all test cases in the entire run (close to 600+tests)

    One possible solution that I am exploring is to write logs using System.Diagnostics.Debug instead of System.Diagnostics.Trace.  Then, on TFS I could build the tests using Release configuration, which should suppress the debug messages being output.  This would still allow me to debug locally using Debug configuration, which will still have trace output being displayed.  I am hoping this will work.



    • Edited by Ken Varn Tuesday, July 16, 2019 1:18 PM
    Tuesday, July 16, 2019 1:18 PM
  • Hi Ken Varn,

    Sorry for delay in reply.

    Did the solution work ? According to your description, I recommend you could log the output message into a file individually, for example txt file. And you could add "#if DEBUG" to judge configuration. When it is under debug, it would log the output message. Please refer the below sample:

    Please refer more about writing log file: How to write log file in C#?

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, July 19, 2019 6:17 AM
  • Dylan,

    Yes, my solution did work.  When using the System.Diagnostics.Debug command, the string is only written to the Output window when compiling with Debug configuration.  

    I already write log output to a file.  My original goal was to be able to see the log lines in the Output window when debugging tests locally, and not have the Output go into the TRX file when running the tests in TFS.  Using the Release configuration for the build when running in TFS disables the System.Diagnostics.Debug  logging, which then cuts down the amount of data written to the TRX file, thus preventing OutOfMemoryException from occurring.

    • Marked as answer by Ken Varn Friday, July 19, 2019 12:40 PM
    Friday, July 19, 2019 12:40 PM