0

From what I know Trace.WriteLine() Writes to all Trace listeners in the Trace.Listeners collection, and after some research I saw that apparently debug.Writeline() does essentialy the same thing. whats then is the point of debug.WriteLine()?

wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • 3
    `Trace.WriteLine()` outputs something for both DEBUG and RELEASE builds. `Debug.WriteLine()` only outputs something for DEBUG builds. Often you don't want to write debug output from a release build, since the end-user can see that if they use any utility that captures debug output. – Matthew Watson Aug 10 '22 at 10:44

1 Answers1

1

This is how the debugging works:

  1. We first use Console.WriteLine for debugging. This will print everything on a Console. Many times, we may not have a console. Also, the purpose of Console.WriteLine (for console applications) is to show meaningful message to the user.
  2. So, then the focus shifts to Debug.WriteLine. Debug.WriteLine prints debug information by default in Visual Studio output window (This can be configured in app.exe.config file). The tracing information is generated with Debug.WriteLine() if built with the DEBUG conditional #ifdef DEBUG. This is "on" by default in debug mode. In release mode, these calls are effectively removed generating no overhead.
  3. However, now we realize we don't want to print everything in Production or release mode (like stack trace etc.) So, then we use Trace.WriteLine in release mode.

In debug mode we can see output from both Debug.WriteLine() and Trace.WriteLine(). Unit Test code however supresses both Debug.WriteLine and Trace.WriteLine calls.

Gauravsa
  • 6,330
  • 2
  • 21
  • 30