Phonegap WP7 Visual Studio 2010控制台日志

5
Phonegap v1.1.0,如何访问console.log(string)的输出?
// provide our own console if it does not exist, huge dev aid!
if(typeof window.console == "undefined")
{
window.console = {log:function(str){window.external.Notify(str);}};
}

// output any errors to console log, created above.
window.onerror=function(e){console.log("Error ::" + e);};

console.log("Installed console ! ");

它将记录到调试输出窗口


谢谢!这帮助我解决了一些烦人的问题 :) - VDP
1个回答

1

console.log 的定义如下

if(typeof window.console == "undefined")
{
    window.console = {
        log:function(str){
            if(navigator.debugConsole){
                navigator.debugConsole.log(str);
            }
            else
            {// In case log messages are received before device ready
                window.external.Notify("Info:" + str);
            }
        }
    };
}

debugConsole.log() 和 window.external.Notify() 的结果都是调用 Debug.WriteLine(msg) 方法。因此,您可以将调试输出重定向到文件中,并保留此信息以便稍后进行调试/查看。不需要连接到 VS 来调试问题,有时这非常有帮助,以下是代码示例:

TextWriterTraceListener[] listeners = new TextWriterTraceListener[] 
{
    new TextWriterTraceListener("debug.log"),
    new TextWriterTraceListener(Console.Out)
};

Debug.Listeners.AddRange(listeners);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接