Debugging in monogame

14,693

Solution 1

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.

Solution 2

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).

Solution 3

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.

Share:
14,693
James G.
Author by

James G.

I learned to program to start my own business. Since then I've worked in various jobs in the web development space and in my free time you can catch me making cool things on the side. I've learned a lot, I still have a lot to learn.

Updated on July 02, 2022

Comments

  • James G.
    James G. almost 2 years

    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.