This might be a nit-picky thing, but in Xamarin when running an Android app, it dumps tons of lines in the console that start with [Mono]
Is there any way to disable these logs?
Thanks in advance
This can be done by changing the state of Monos execution environment on the device; which is just a set of environment variables that alters Monos behaviour (be it garbage collection, logging etc). In this case, to alter the logging behavior we need to modify the values stored in the environment variables MONO_LOG_LEVEL
and MONO_LOG_MASK
.
Xamarin.Android offers 2 mechanisms developers can use to change the execution environment:
adb shell setprop debug.mono.env
. This can be done as a post build action.I prefer to use method 2 as it's easier to edit a text file than changing build actions. Do this using the steps outlined below.
Add a plain text file called environment.txt
to the root path of your Xamarin.Android project.
Right click on environment.txt
and set its build action to AndroidEnvironment
.
The environment file is series of key=value pairs seperated by newlines. For logging, we can set the following variables:
MONO_LOG_LEVEL
MONO_LOG_MASK
For example, we can ignore most messages by filtering MONO_LOG_LEVEL
by error:
environment.txt
MONO_LOG_LEVEL=error
Background reading:
What I do is below. It's still imperfect as the window holds 10k logs, including the hidden ones, so mine eventually disappear. Additionally, I can't seem to copy from the window.
1) Use a tag of "AAA" for all my logs.
2) View the output in Tools>Android>Device Log
3) Sort alphabetically by Tag.
4) I find that the outputs beneath mine are still distracting. I can click the "filter" for the Tag and uncheck everything but mine. Annoyingly, I have to repeat this step periodically as new tags are not filtered by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With