We have the following code:
private async Task GetLogsAndWrite()
{
_logger.Flush();
var logFiles = Directory.GetFiles(AppConstants.NLogDefaultPath);
var logs = new List<string>();
foreach (var log in logFiles)
{
logs.Add(await File.ReadAllTextAsync(log));
}
if (logs is not null && logs.Any())
{
foreach (var log in logs)
{
var logFileName = ("MyLog" + DateTime.Now.ToString("yyyy-MM-ddTHH_mm_ss")).Replace(" ", "") + ".txt";
WriteToFile(log, logFileName);
}
}
}
So the challenge I am facing is that when the log files upload – I am not getting all the data. I know this for a fact because one of the last things logged in the app before the logs are uploaded – is that the log files are being uploaded.
An interesting thing is that, if I keep trying to upload — after a period of time (at least 5-10 minutes) an additional log file is found on the device which contains the most recent data (i.e. the data I was missing). That additional file is then included in the upload and I then have all the information.
How can I force NLog / Android / Maui to basically close everything and send ALL the data / log files?
It is very spotty to replicate but here is what I just did that replicated the challenge:
I ran my application yesterday and did a few things that got logged. I closed the application. Today, I started the application again, and performed some actions that are logged. Then I attempted to upload the logs and I did not get the information from today. Only the information from yesterday.
Any ideas would be greatly appreciated.