Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

logging - Xamarin Android - Turn off Mono Logs

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

question from:https://stackoverflow.com/questions/26760798/xamarin-android-turn-off-mono-logs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  • 1. Using adb shell setprop debug.mono.env. This can be done as a post build action.
  • 2. Using an environment build file to change the execution environment state per project.

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.

Adding An Environment File

Add a plain text file called environment.txt to the root path of your Xamarin.Android project. enter image description here

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

  • debug
  • info
  • message
  • warning
  • critical
  • error

MONO_LOG_MASK

  • asm
  • dll
  • cfg
  • all
  • type
  • gc

For example, we can ignore most messages by filtering MONO_LOG_LEVEL by error:

environment.txt

MONO_LOG_LEVEL=error

Background reading:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...