Should I write to log file every time transaction item is processed? or only once at the end?

I have this big data in Excel file, and I will have to process each line one at a time. I would say there are about 2000+ lines of data to process. It takes more than a few hours to complete the execution.

Now, I wonder if I should write log info into a file every after one transaction item is processed, or just do it once in End state (I am using REFramework).
I thought using “Write Range” activity every time one piece of transaction item is processed, is too much, because that means the system will keep writing to a file every few minutes for a few hours.

So what I am doing is, every after transaction, I save the log info as DataRow into a DataTable designated for log. And in End State, I write into a file using Write Range activity only once. This will cover both the case when everything was successful, or the case when there was an error in the middle of Process state because End State will occur no matter what.

But the problem is, if you are running the robot, and something happens that makes you have to stop the execution halfway through, there won’t be any log saved because End state hasn’t happened yet.

Which should be better for cases like mine?

It depends on what you value more: processsing time or stability.

If you write to the file once at the end, your items will be processed more quickly, since a datatable is updated quickly, and writing to a file takes more time. However, if you want a solution that ensures that the data is logged even in the event of a power failure or other catastrophe, you’ll want to write to the file after every transaction.

If you are writing this log in excel, then (if you must use excel) use the write cell and the workbook activity, without the excel scope to write at each transaction end, this will be a lot faster and not an issue with added time.