This turned out to be my "simplest" solution! https://wandering.shop/@xgranade/112961883517691345
It does turn out "Debug.Listeners" was renamed to "Trace.Listeners" in .NET CORE so the actual solution is just stuffing these two lines at the top of the program:
var myWriter = new TextWriterTraceListener(System.Console.Out);
Trace.Listeners.Add(myWriter);
@[email protected] Does it work to add System.Console.Out as a trace listener? https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.debug.listeners?view=netframework-4.8.1#examples (I have no idea why the docs keep redirecting to .NET Framework 4.8.1 instead of .NET neé .NET Core.)
@mcc
I used DuckDuckGo to search:
dotnet core debug.print -"VS code" -"Visual Studio"
The third link was: https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-stack
Which led me to:
https://learn.microsoft.com/en-us/dotnet/core/diagnostics/tools-overview?source=recommendations
Which suggests VSCode... but also mentions:
https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-sos
Which supposedly supports lldb?
I then used DDG to search:
dotnet core sos debug print
Which led to this blog post:
https://devblogs.microsoft.com/premier-developer/debugging-net-core-with-sos-everywhere/
Good luck!
@onelson I have vs code on this machine but there's an awkward issue where we've already got separate, unique vs code execution scripts set up for Windows and Mac hosts and this raises the question of (1) will the Mac launch.json simply work on linux? (2) will the Mac launch.json need modification to work on Linux? (3) will the Mac launch.json do something *subtly but silently wrong*, such as misinvoke msbuild prebuild steps, on Linux?
Simple to test but simpler to ask Christine to test it!
@mcc @onelson not quite a noop, it goes to syslog
https://github.com/dotnet/runtime/blob/b1968e7aa8d56a088e8be6817d5240fb345f901c/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs#L48
e.g.
`Debug.WriteLine("this is some output " + DateTime.Now.ToString(), "foo");`
`$ tail -F /var/log/syslog`
...
`Aug 14 14:38:29 sandsys dotnet_hell: foo: this is some output 2024-08-14 2:38:29 p.m.`
@onelson @mcc "editing a key in the linux registry" alol.
but to be serious, it's syslog output so a variety of syslog implementations are available and most of those you can configure to deliver different categories of output a variety of different ways to different targets (e.g. different files, devices, etc.) or not
@mcc I think you can type `dotnet new` to bootstrap a project. And then `dotnet run` to run it.
It’s been a while since I’ve done C# on Linux.
@mcc Does it work to add System.Console.Out as a trace listener?
(I have no idea why the docs keep redirecting to .NET Framework 4.8.1 instead of .NET neé .NET Core.)
lol
The main thing I work on is still using .Net Framework 4.8 - because we just don't have the staff or time to sink a big effort into upgrading - so of course any time *I* try to look anything up, Microsoft directs me to the documentation for the latest .NET aka Core.
MS must be doing some very sophisticated context tracking to so consistently send users to the wrong docs version.
@mcc Before you call Debug.Print, try adding these lines:
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.AutoFlush = true;
(I'm using .NET 8)
@mcc Super simple examples:
This just outputs "Hello, World!":
private static void Main(string[] args)
{
Debug.Print("This is a debug message.");
Console.WriteLine("Hello, World!");
}
This outputs "This is a debug message." and "Hello, World!":
private static void Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.AutoFlush = true;
Debug.Print("This is a debug message.");
Console.WriteLine("Hello, World!");
}
Microsoft Learn does is the source of all the good docs - https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build
TL;DR; The '-tl:auto' parameter is the answer - tl == 'terminal logging'