Solution
This issue can be related to a function that is not being concluded, when its process is interrupted, the functions can present unknown information, with some other factors affecting such as how the Operating System handles the memory, the tasks that it accomplishes, and the order on how the functions are processed in the moment of the unexpected events such as any interruption that can appear.
This can happen at any moment if there is an open reference to a file and the process is interrupted by a system shutdown or a crash, as if in the moment when the issue of the crash occurs the data being written is incomplete, inconsistent, or incomplete data can be found in the file.
There is no direct solution that can be performed for this issue, as there is always a chance that the crash or shutdown can happen when the reference to the file is opened.
However, the main recommendation existing for this kind of behavior is to have a contingency strategy for the shutdowns or crashes, but there is another strategy that can be applied for these situations and it could be to use the
Flush File function, which will guarantee that the data you wanted to log will be present in the file. Please bear in mind that this function can slow down the performance of the programming, but it is highly recommended if these issues need to be avoided when the reference to the file is not opened.