[FIXED] Where to store NLog log files on Xamarin Android?


In a tutorial, I followed some steps to integrate NLog into our Xamarin (non Forms) application. In there the folder to store the log files is ${specialfolder:folder=MyDocuments}. If I change that folder to e.g. /sdcard/Download I see that a logs folder is created and I can access / copy the log files.

C:\Users\bachph>C:\Android\android-sdk\platform-tools\adb.exe pull /sdcard/Download/logs/ D:\temp
/sdcard/Download/logs/: 2 files pulled. 5.4 MB/s (2077256 bytes in 0.370s)

If I now change the folder back to ${specialfolder:folder=MyDocuments} and print the path to that folder

LogManager.GetCurrentClassLogger().Info("NLog.config loaded. Application Start.");
LogManager.GetCurrentClassLogger().Info($"NLog logs to {Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}");

I can’t see the data in the shell nor can I access / copy them from that folder. I’m now not sure if I Android just permits the access to the folder / files or if NLog can’t write to that folder.

Any ideas?

Edit: internal trace log output

2019-10-07 11:39:47.6959 Debug FileTarget(Name=f): Process file '/data/data/de.app.debug/files/logs/app-2019-10-07.log' on startup
2019-10-07 11:39:47.7298 Debug Creating file appender: /data/data/de.app.debug/files/logs/app-2019-10-07.log
2019-10-07 11:39:47.7377 Debug Mutex for file archive not supported
2019-10-07 11:39:47.7439 Trace Opening data/data/de.app.debug/files/logs/app-2019-10-07.log with allowFileSharedWriting=False
2019-10-07 11:39:47.6440 INFO App.Activities.Base.MainActivity NLog.config loaded. Application Start.


I found a way to access the data inside of the /data/data folder. Unfortunately it is a bit tricky to accees the data.

First of all the “run-as” command does not work on my device. So I have to create a “Backup” to get all data from the app.

You can create a backup with:

adb.exe backup -f D:\temp\backup.ab -noapk de.app.debug
adb.exe backup -f <path-to-local-file> -noapk <app-base-package>

You will be promt to confirm the action on your device. Optionally you can chose a password for the backup file.

That will create an android backup. To access the data inside the backup file, you need the help of a java archive. Get the latest abe-all.jar from there.

You can now convert the android backup into a tar archive with

java -jar abe-all.jar unpack backup.ab backup.tar [optional-password]

Then simply extract the newly created backup.tar file. You’ll find all data from your app package in there.

Answered By – bachph

Answer Checked By – Terry (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published