简体   繁体   English

在 Xamarin Android 上的哪里存储 NLog 日志文件?

[英]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.教程中,我按照一些步骤将 NLog 集成到我们的 Xamarin(非表单)应用程序中。 In there the folder to store the log files is ${specialfolder:folder=MyDocuments}.在那里存储日志文件的文件夹是 ${specialfolder:folder=MyDocuments}。 If I change that folder to eg /sdcard/Download I see that a logs folder is created and I can access / copy the log files.如果我将该文件夹更改为例如 /sdcard/Download 我会看到创建了一个日志文件夹,我可以访问/复制日志文件。

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如果我现在将文件夹改回 ${specialfolder:folder=MyDocuments} 并打印该文件夹的路径

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.我看不到 shell 中的数据,也无法从该文件夹访问/复制它们。 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.我现在不确定我 Android 是否只允许访问文件夹/文件,或者 NLog 是否无法写入该文件夹。

Any ideas?有任何想法吗?


Edit: internal trace log output编辑:内部跟踪日志 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.我找到了一种访问 /data/data 文件夹中数据的方法。 Unfortunately it is a bit tricky to accees the data.不幸的是,访问数据有点棘手。

First of all the "run-as" command does not work on my device.首先,“run-as”命令在我的设备上不起作用。 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.这将创建一个 android 备份。 To access the data inside the backup file, you need the help of a java archive .要访问备份文件中的数据,您需要java 存档的帮助。 Get the latest abe-all.jar from there.从那里获取最新的 abe-all.jar。

You can now convert the android backup into a tar archive with您现在可以将 android 备份转换为 tar 存档

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

Then simply extract the newly created backup.tar file.然后只需提取新创建的 backup.tar 文件。 You'll find all data from your app package in there.您会在其中找到来自您的应用 package 的所有数据。

Alternative way of accessing log-files on Xamarin platform is to save in special-folder My Documents.在 Xamarin 平台上访问日志文件的另一种方法是保存在特殊文件夹 My Documents 中。

https://docs.microsoft.com/en-us/xamarin/android/platform/files/ (See System.Environment.SpecialFolder.MyDocuments ) https://docs.microsoft.com/en-us/xamarin/android/platform/files/ (参见System.Environment.SpecialFolder.MyDocuments

NLog has ${specialfolder:folder=MyDocuments} . NLog 有${specialfolder:folder=MyDocuments} See also https://github.com/NLog/NLog/wiki/Special-Folder-Layout-Renderer另请参阅https://github.com/NLog/NLog/wiki/Special-Folder-Layout-Renderer

Then make a feature in the application to read the current log-file from the folder, and send to email-app or make http-upload (Or just show the log-content directly in the application-about-dialog)然后在应用程序中创建一个功能以从文件夹中读取当前日志文件,并发送到电子邮件应用程序或进行 http-upload (或者直接在应用程序-about-dialog 中显示日志内容)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM