2012-07-20 63 views
0

我有一个芒果版WP7应用程序。当我通过应用程序部署工具将应用程序部署到手机时,我无法获取错误日志或日志报告。我需要日志来检查后面发生的事情。这一点很重要。我怎样才能做到这一点?有没有办法获得记录并获取正在运行的应用程序的日志?我使用记录语句如下:手机从PC断开时获取错误日志

#if LOG_ENABLED 
           Logger.log(TAG, "Client not received any UserId from server response.. so Exiting the application."); 
#endif 

和记录器类是这样实现的:

public static void log(string tag, string str) 
    { 
#if LOG_ENABLED 
     string strMsg= new StringBuilder().Append(DateTime.Now.ToShortDateString()).Append(" , ").Append(DateTime.Now.ToShortTimeString()).Append(" : ").Append(tag).Append(" : ").Append(str).ToString();    
     System.Diagnostics.Debug.WriteLine("Telus Application log : "+strMsg);   
     // LogOffline(strMsg); 
#endif 
    } 

internal static void log(Exception e) 
    { 
#if LOG_ENABLED 
     System.Diagnostics.Debug.WriteLine("Telus Application log : {0}", e.StackTrace); 
#endif 
    } 

我没有问题,得到日志的模拟器运行或者,即使应用程序部署时通过Visual Studio打电话。

谢谢! :)

回答

1

一个解决方案是将日志写入IsolatedStorage。然后,您可以通过使用IsolatedStorageTool来访问IsolatedStorage,或者您可以将一个选项添加到应用程序中,以显示它在应用程序中。

0

据我所知,System.Diagnostics.Debug.WriteLine只有当调试一个应用程序(当然Visual Studio中需要连接到Windows Phone模拟器或设备)输出在Visual Studio输出窗口中的消息。

+0

我收到日志,并没有问题。当设备(电话)未连接到VS时,我想获取日志。 – Apoorva 2012-07-20 10:43:44

+1

在这种情况下,你应该在@GnrlKnowledge所说的孤立存储中写入日志。以下是如何读取和写入独立存储中的文本:http://www.windowsphonegeek.com/tips/all-about-wp7-isolated-storage-read-and-save-text-files。另一个解决方案是使用LittleWatson类。它将帮助您报告例外情况:http://blogs.msdn.com/b/andypennell/archive/2010/11/01/error-reporting-on-windows-phone-7.aspx – 2012-07-20 12:35:16

+0

Thnx !!! :)会尝试。 – Apoorva 2012-07-20 13:34:31