Console writeline does not work
Asked Answered
T

3

11

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

Twopence answered 26/1, 2018 at 12:50 Comment(6)
The output window isn't the consoleCattan
You mean Debug.WriteLineMagnetite
use Debug.WriteLine insteadStoppage
Console.WriteLine or Debug.Writeline are inappropriate for tracing or logging. Use a proper logging libraryCattan
BTW Debug.WriteLine won't work in Release builds.Cattan
Console.WriteLine() works fine, but for some project it does not. With WPF + .Net Framework it works, with WPF + .Net Core 3 it does not.Almund
S
17

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

Scout answered 26/1, 2018 at 12:53 Comment(3)
Only for debug builds thoughCattan
Also remember that you need DEBUG flag to use this. see HERETriecious
Oh man, I totally forgot which one to use. Why doesn't Console.WriteLine throw an error when there's no console?Expediential
C
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.

Cattan answered 26/1, 2018 at 13:4 Comment(0)
U
3

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.

Udometer answered 26/1, 2018 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.