Debugging in monogame

こ雲淡風輕ζ 提交于 2019-12-23 10:28:17

问题


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.


回答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.




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




回答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.




回答4:


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.



来源:https://stackoverflow.com/questions/19943247/debugging-in-monogame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!