【问题标题】:Xamarin Android - Print to the application output in Release modeXamarin Android - 在发布模式下打印到应用程序输出
【发布时间】:2016-08-03 15:42:56
【问题描述】:

要在三星和 wiko 设备上修补 some crash,我必须在设备上以发布模式运行我的应用程序。但我想在应用程序输出中看到System.Diagnostics.Debug.WriteLine 的输出。

我已启用开发人员工具,并在选项中定义了 DEBUG 常量;我可以设置断点,但是控制台中仍然没有显示 WriteLine 输出。

我该怎么办?

【问题讨论】:

  • FWIW:“我已启用开发人员工具,并在选项中定义了 DEBUG 常量” - 如果您进行了这些更改,那么您所拥有的实际上不再是“发布”模式.时间不同,并且 JIT 被禁用(因为您附加了调试器)。最好不要进行这些更改 - 您仍然可以使用 Android Log 输出到 logcat,如答案中所述。

标签: logging xamarin xamarin.android


【解决方案1】:

对于Xamarin.Android,使用Android 的Log 实用程序并观察/过滤logcat 输出的消息。

示例:

string TAG = "StackOverflow";
Log.Info(TAG,  $"This is a Info message: {DateTime.Now}");
Log.Debug(TAG, $"This is a debug message");
Log.Warn(TAG,  $"Warning! Warning! Will Robinson Warning! Warning!");
Log.Error(TAG, $"Error, contact support with error code 99 for assistance");

Logcat 输出(通过命令行或 Android 设备监视器):

>adb logcat |grep StackOverflow

08-03 11:58:46.282  2338  2338 I StackOverflow: This is a Info message: 8/3/2016 11:58:46 AM
08-03 11:58:46.282  2338  2338 D StackOverflow: This is a debug message
08-03 11:58:46.282  2338  2338 W StackOverflow: Warning! Warning! Will Robinson Warning! Warning!
08-03 11:58:46.282  2338  2338 E StackOverflow: Error, contact support with error code 99 for assistance

【讨论】:

  • 正如他所说。使用依赖服务来使用本机 API 来编写日志,不要为此使用 System.Diagnostics.Debug.WriteLine。在您的 Dependency 服务中,您甚至可以检查 DEBUG 标志以仅在 DEBUG 标志打开时进行记录,从而获得与 System.Diagnostics.Debug.WriteLine 相同的行为(您当然可以在需要时修改行为)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-01
  • 1970-01-01
相关资源
最近更新 更多