Displaying Debug Information for Managed COBOL

You can use the WriteLine method of the System.Diagnostics.Debug class of the .NET framework with your managed applications to display debug information such as diagnostic messages in the Output window during debugging or execution of the application.

The System.Diagnostics.Debug class only works with Debug build configurations and does not take effect when you build the application for Release.

The following is an example of how to utilize the WriteLine method of the System.Diagnostics.Debug class:

  1. Invoke the WriteLine method from your code:
           program-id. Program1.
    
           data division.
           working-storage section.
           01 var pic x.
           procedure division.
               invoke type System.Diagnostics.Debug::WriteLine("Hello World")
               accept var.
               
               goback.
               
           end program Program1.

    The WriteLine method is declared with a conditional attribute, ConditionalAttribute("DEBUG") which means the application only invokes the method if you set the DEBUG constant for your project, and then build the project for Debug.

  2. Set the DEBUG constant for your managed project as follows:
    1. In Visual Studio, click Project > MyProject Properties.
    2. Click the COBOL tab.
    3. Ensure Define DEBUG constant is checked.
  3. On the COBOL tab in the project properties, ensure Configuration is set to DEBUG.
  4. Build your project, and then start debugging.

    The application writes the debug information in the Output window.

If you do not set the Debug constant, or if you build the project for Release, the application ignores the method and does not write any debug information in the Output window during execution.

For more information on how to use the System.Diagnostics.Debug class, go to the MSDN.