Debugging in monogame
Asked Answered
T

4

9

How do you print or output text in Monogame?

I googled how to display text in monogame and was led to this: Debug.WriteLine

Which says: "By default, the output is written to an instance of DefaultTraceListener."(and that page just confused me more).

So, if someone could direct me to a method of displaying DefaultTraceListener, or another method of outputting text in monogame, I would appreciate it.

Toomer answered 13/11, 2013 at 1:0 Comment(0)
T
12

I found it!

Using Debug.WriteLine writes to the debugger, which is in the output window in Visual Studio(by default at the bottom). It appears when you close the program(press F5 to start, Esc to close) by default in an OpenGL project.

Toomer answered 13/11, 2013 at 4:13 Comment(0)
G
9

If you like, you can use Console.WriteLine like you would in a normal C# console application, assuming you're developing a desktop application. There are a couple of steps.

  1. Open the Properties for your MonoGame project
  2. Select the Application tab
  3. Change the Output Type to Console Application.

Your application should run as normal, only a console window should appear when you start the game.

Alternatively, you can use Debug.WriteLine, which will write to the output window in Visual Studio (it should appear when you start debugging your game).

Greathearted answered 18/8, 2016 at 6:12 Comment(0)
B
2

If you use the standard Debug.WriteLine or Trace.WriteLine, then output goes to the default trace listener which can be viewed in the Visual Studio output window. Outside of Visual Studio, you can use programs such as DebugView (SysInternals) or LogFusion (Binary Fortress) to display the output. DebugView even has a feature for viewing debug output from a remote machine.

There are other trace listeners that can send output to a file, or to the Windows event log, or you can write your own trace listeners fairly easily.

You could also consider using a ready-made logging framework such as NLog, which would give you a great deal of flexibility. I have found in practice that using NLog turns out to be a lot easier than the built in stuff in .NET, because of the way it lets you easily reconfigure things and control/filter the output in a much more flexible way.

Briones answered 23/9, 2015 at 23:55 Comment(0)
T
0

I know this has been answered, but if anyone else stumbles upon this, you can also use Console.Write(thing in here); or Console.WriteLine(thing in here); to write to the console window. WriteLine adds a line ending and Write does not.

Triglyceride answered 25/2, 2015 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.