F FabioG Active Member Licensed User Longtime User Nov 11, 2013 #1 Hello, 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 Code: Copy 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
Hello, 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 Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Nov 11, 2013 #2 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. Upvote 0
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.
DonManfred Expert Licensed User Longtime User Nov 12, 2013 #4 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... Upvote 0
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...
eps Expert Licensed User Longtime User Nov 12, 2013 #5 DonManfred said: 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... Click to expand... 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. Upvote 0
DonManfred said: 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... Click to expand... 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.