I am printing a lot of lines in my log while debugging like this:
System.Diagnostics.Debugger.Log(0, null, responseFromServer);
System.Diagnostics.Debugger.Log(0, null, t[0]);
....
All of them are getting printed at the same line.. How can i make them print in seperate lines?
I tried using
System.Diagnostics.Debugger.Log(0, null, t[0]+"\n");
But, it didnt work. Any help will be appreciated . Thanks
In .NET the idiom
Environment.NewLineis aSystem.Stringthat consists of the properSystem.Char(s) to terminate a line of text, so:[Updated 2015-05-07]
Reflecting upon this a few years on, i feel like i dropped the ball on this at least a little bit (though, i do think that it’s important to be able to do the low-level NewLine without having to fight the language sometimes as well; so i also like the original answer…)
First off, David Brown did give a good answer below: using
System.Diagnostics.Debug.WriteLine(andWrite) instead. That is a good solution to this, especially in the case of the OP, as the other parameters of the call aren’t even really being used; and theDebug.Write/WriteLinecalls looks like this (using for examples the OP’s original calls, assuming for the sake of example that the OP’s original first parameterresponseFromServerwas already terminated, and the second needed termination):Easy peasy.
Better yet though, why not
Trace?I will just point you to this stackoverflow question here but here’s the gist.
You can set up in your App.config but, of course you can also just create it all programatically as well, since the app.config sections simply create objects!
Something like:
⋮ <trace> <!-- note: notional notation only --> <add name="consoleLog" logLevel="debug" enabled="" type="⋯ <add name="netLog" logLevel="verbose" enabled="false" addr="rdp://127.0.0.1:1935/nothing/stream" type="⋯ <add name="fileLog" logLevel="errors" enabled="true" file="c:\boots.ini" type="⋯ </trace> ⋮and then your code calls
Trace()just likeDebug().Yep, it’s multi-target; and you can set it up to be multi-target, and you can either use built-in
System.DiagnosticsTracetypes (like aConsoletracer if you want to print to the screen, for example) or you can create your own custom types as necessary. Beautiful!Last word: both Debug and Trace have lots of helper functions that are there to make whatever writes you’re doing more symbolic; WriteLineIf, TraceError, etc. and it pays to play around with them until you figure out why they are there. It’s almost guaranteed that the more you use them, the more useful you will find them. ♡