Windows Phone開發(fā)調(diào)試中顯示日志
開發(fā)過程中,需要使用log來記錄程序運行狀態(tài)。
WP7 SDK給出一個在debug模式下打印日志的方法。VS開發(fā)中默認就是debug模式,我們要做的就是調(diào)用打印日志的方法。
Debug.WriteLine(String logMsg)
使用方法:
引入命名空間:
1: using System.Diagnostics;
然后就可以再想要打印日志的地方使用 Debug.WriteLine方法打印日志,參數(shù)是日志內(nèi)容。
1: Debug.WriteLine("LogText");
想要看到日志需要打開output窗口
測試代碼(XNA程序):
給Game1.cs的update方法中添加打印日志語句(測試例子是每秒鐘打印1條日志)
- int timeFlag = 0;//程序運行時間標(biāo)識
 - protected override void Update(GameTime gameTime)
 - {
 - // Allows the game to exit
 - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
 - this.Exit();
 - // TODO: Add your update logic here
 - if ((int)gameTime.TotalGameTime.TotalSeconds == timeFlag)
 - {
 - Debug.WriteLine("LogText");
 - timeFlag++;
 - }
 - base.Update(gameTime);
 - }
 
















 
 
 

 
 
 
 