8

I'm debugging a UWP in C#. On a certain moment the console stops giving me the write line content.

Does anyone can imagen what the problem could be?

enter image description here

Belekz
  • 480
  • 1
  • 7
  • 18

3 Answers3

13

The Console.WriteLine isn't for IDE output window. It writes to console. So, you could use Debug.WriteLine() which is available in System.Diagnostics

lucky
  • 12,734
  • 4
  • 24
  • 46
4

Console.WriteLine or Debug.Writeline are inappropriate for tracing or logging. The real solution is to use a logging library.

The Output Window of the debugger is not the console. If you want to write to it use Debug.WriteLine. You can do this because the Output Window is registered as a listener for .NET's tracing infrastructure.

This won't work in Release mode though. You'd need to use Trace.WriteLine for this but you'd also need to register your own listeners. You'd also need to specify message levels to separate errors from verbose messages and eg write only erros to log files.

At this point though, it's just as easy to add and configure a logging library like Serilog or NLog that have providers for rolling files, databases, logging servers etc.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
2

If you wanna see some messages in "Output" you should use Debug.WriteLine. For this add using System.Diagnostics.

If you use WindowsForm, for example, you can't just use Console.WriteLine.

v.slobodzian
  • 453
  • 6
  • 16