• 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

    作者:Lighting Cui

    出处:http://tugeler.cnblogs.com/

    本文版权归作者所,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    第1章:程序设计和C语言(C语言入门)
    倒计时IE6+
    uploadify 使用 详细 说明
    HTTP 错误
    asp.net 向后台提交 html 代码段 包括 <> 标签
    C#使用NLog记录日志
    IE浏览器 location.href 不跳转
    .Net Core 导出Excel
    .net mvc 获取acion 返回类型
    sql sever 执行较大的文件脚本
  • 原文地址:https://www.cnblogs.com/tugeler/p/2254799.html
Copyright © 2020-2023  润新知