Skip to main content.

公告

搜索

最新评论

Windows Phone 7在调试过程中显示日志

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

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

Debug.WriteLine(String logMsg)

使用方法:

引入命名空间:

1: using System.Diagnostics;
然后就可以再想要打印日志的地方使用 Debug.WriteLine方法打印日志,参数是日志内容。
1: Debug.WriteLine("LogText");
想要看到日志需要打开output窗口

就会显示出来output窗口

测试代码(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:         }
结果如下:

原文链接:http://www.cnblogs.com/tugeler/archive/2011/11/19/2254799.html

Feedback

你还可以输入600/600个字符 发表评论
称呼: (必填) 登录 | 开通博客
邮箱: (选填) 你的邮箱地址不会被公开
网站: (选填)
验证码: (必填)