3

To patch some crash on samsung and wiko devices, I have to run my application on device in Release mode. But I would like to see the output of System.Diagnostics.Debug.WriteLine in the application output.

I've enabled developer instrumentation, as well as defined the DEBUG constant in the options ; I can set breakpoints, but the WriteLine outputs still aren't shown in the console. Debugging options

other debugging options

How can I do ?

Community
  • 1
  • 1
Eino Gourdin
  • 4,169
  • 3
  • 39
  • 67
  • FWIW: "I've enabled developer instrumentation, as well as defined the DEBUG constant in the options" - if you make those changes, what you have is, in effect, no longer "Release" mode. The timing is different, and JIT is disabled (because you've attached a debugger). Better to NOT make those changes - you can still use Android Log output to logcat as mentioned in the answer. – ToolmakerSteve Jun 26 '18 at 03:40

1 Answers1

8

For Xamarin.Android use Android's Log utility and watch/filter the logcat output for your messages.

Example:

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 Output (via cmd-line or 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
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • 2
    Just as he says. Use dependency services to use the native APIs to write your logs, don't use `System.Diagnostics.Debug.WriteLine` for this purpose. In you Dependency service, you can even check for the `DEBUG` flag to log only if DEBUG flag is on and thus get the same behaviour than `System.Diagnostics.Debug.WriteLine` (behaviour that you can of course modify when you need it). – Thibault D. Aug 04 '16 at 06:52