use this code to write log events of my app on file
this works well thus special adds a new row at the end of file
is there a way to affiungere new riche beginning of the file?
in order to have the latest events at the top and not at the end?
thanks
Fabio
B4X:
Sub LogWrite(EventsLog As String)
Log(EventsLog)
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirInternal, "MyLog.log", True))
TextWriter1.WriteLine("- " & EventsLog)
TextWriter1.Close
End Sub
The file system doesn't allow you to "insert" a string to a file. You can only append to an existing file.
You will need to read the complete file, insert the line to the list and write the complete list. As an alternative you can write the logs to a List and only save it periodically.
Alternatively you also can write the log to a sqlite-db and then, when needed, you can show only the last line. Or even show all entries in reverse order...
Alternatively you also can write the log to a sqlite-db and then, when needed, you can show only the last line. Or even show all entries in reverse order...
This, I was wondering if you could just present the information from the file in a different order. Using a DB as an intermediary step could be good, or possibly a list, listview, scrollview or some other similar container and present the data in reverse order as it were or get a few lines at a time, keep a placeholder and page through the file in reverse order.