[FIXED] How to use NLog in Xamarin Android


I want to use NLog in my Xamarin.Droid project. I installed NLog.Config and dependencies and move NLog.config and NLog.xsd manually to Assets folder and change NLog.config build action to AndroidAsset.

As you can see in Load automatically NLog.config from Assets folder I guess there is no problem to put NLog.config into Assets folder.

After that I change NLog.config like below

    <target name="console" xsi:type="Console" layout="${longdate} ${callsite} ${level} ${message}"/>
    <logger name="*" minlevel="Info" writeTo="console" />

After that I write some code like below for write some log in Console

ILogger logger = LogManager.GetCurrentClassLogger();
for (int c = 0; c < 1000; ++c)
    logger.Debug("Hi there");

But after that I could not see any my messages in Android Device Logging or Output tab when “Show output from” set to Debug.

Do I look to the right places?


Your config says minlevel info:

<logger name="*" minlevel="Info" writeTo="console" />

but your are writing debug level. Which is below info.

logger.Debug("Hi there");

So change your logger rule to: (level name & attribute names are case insensitive)

<logger name="*" minlevel="debug" writeTo="console" />

Answered By – Julian

Answer Checked By – Marie Seifert (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published