WP7 在调试过程中显示日志

开发过程中,需要使用log来记录程序运行状态。

WP7 SDK给出一个在debug模式下打印日志的方法。VS开发中默认就是debug模式,我们要做的就是调用打印日志的方法。

Debug.WriteLine(String logMsg)

使用方法:

引入命名空间:

   1: using System.Diagnostics;

然后就可以再想要打印日志的地方使用 Debug.WriteLine方法打印日志,参数是日志内容。

   1: Debug.WriteLine("LogText");

想要看到日志需要打开output窗口

image

就会显示出来output窗口

image

测试代码(XNA程序):

给Game1.cs的update方法中添加打印日志语句(测试例子是每秒钟打印1条日志)

   1: int timeFlag = 0;//程序运行时间标识
   2:         protected override void Update(GameTime gameTime)
   3:         {
   4:             // Allows the game to exit
   5:             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
   6:                 this.Exit();
   7:  
   8:             // TODO: Add your update logic here
   9:             if ((int)gameTime.TotalGameTime.TotalSeconds == timeFlag)
  10:             {
  11:                 Debug.WriteLine("LogText");
  12:                 timeFlag++;
  13:             }
  14:  
  15:             base.Update(gameTime);
  16:         }

结果如下:

image

posted @ 2011-11-19 01:59  LightingCui  阅读(1187)  评论(2编辑  收藏  举报