Xamarin Android - 在发布模式下打印到应用程序输出

Ein*_*din 3 logging xamarin.android xamarin

为了修补三星和wiko设备上的一些崩溃,我必须在发布模式下在设备上运行我的应用程序.但我想看看System.Diagnostics.Debug.WriteLine应用程序输出中的输出.

我启用了开发人员检测,并在选项中定义了DEBUG常量; 我可以设置断点,但WriteLine输出仍未显示在控制台中. 调试选项

其他调试选项

我能怎么做 ?

Sus*_*ver 6

对于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");
Run Code Online (Sandbox Code Playgroud)

Logcat输出(通过cmd-line或Android Device Monitor):

>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
Run Code Online (Sandbox Code Playgroud)

  • 就像他说的那样.使用依赖服务来使用本机API来编写日志,不要为此使用`System.Diagnostics.Debug.WriteLine`.在Dependency服务中,您甚至可以检查`DEBUG`标志是否仅在DEBUG标志打开时记录,从而获得与`System.Diagnostics.Debug.WriteLine`相同的行为(当然您可以在需要时修改它的行为)它). (2认同)