Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Descrease debug output level at Xamarin.Android + Visual Studio

Sorry for lame and easy question but I failed to find an answer to it. Every time I print something to the System.Diagnostics.Debug.WriteLine I have my message tripled:

System.Diagnostics.Debug.WriteLine("test");

Output:

[0:]
test
[0:] test 
10-22 19:57:13.981 I/mono-stdout( 1026): test 

I'm stick to System.Diagnostic.Debug because I write messages from both UI part (monodroid) and business logic (PCL)

Is there any way to descrease level of debug noise of Xamarin.Android?

Thank you for any suggestions.

like image 770
Alexey Strakh Avatar asked Mar 22 '23 23:03

Alexey Strakh


2 Answers

Make your own little abstraction. We have the same issue in our project, this little Interface helps:

public interface ILogger
{
    void Write(LogLevel level, String tag, String message);
}

Then you have your Loggers for each platform, for example:

public class AndroidLogger: ILogger
{
    public void Write(LogLevel level, string tag, string message)
    {
        Android.Util.Log.WriteLine(ConvertLogLevel(level), tag, message);
    }
}

You inject the logger in the iOS/Android project and you can even create fancy logger like e.g. a nice file-logger for iOS:

#if DEBUG
LOG.AddLogger(new TouchFileLogger());
LOG.AddLogger(new ConsoleLogger());
#endif

The LOG-class is static and needs not to know about the implementations, thats why it can be easily used in your shared PCL library.

Hope that helps, despite your problem might be solved by now ;-)

like image 55
Ursin Brunner Avatar answered Mar 24 '23 14:03

Ursin Brunner


You can use Android.Util.Log instead, this greatly decreases it. It also has different levels of logging which you can filter in logcat.

  • Info: Log.Info()
  • Debug: Log.Debug()
  • Warning: Log.Warn()
  • Error: Log.Error()
  • Verbose: Log.Verbose()

and additionally a WriteLine, which does all of the above:

Log.WriteLine()
like image 45
Cheesebaron Avatar answered Mar 24 '23 12:03

Cheesebaron