Resilient Programming using the SD Card Library

Hi,

I have a project which requires writing some logged data to an SD card. I use the SD Library in Arduino. However, my issue is, that this logging device I have the SD card wired up to requires it to be shut off every ten seconds to restart. This is by design. However, what happens is that sometimes the data gets corrupted on the SD Card requiring me to reformat. How do I go programming the SD card to log safely avoiding any corruption. I flush the data every 500 bytes roughly, is the problem happening that a restart is occuring midflush? How do I avoid this happening, is there anyway to detect the clicking of a reset button on my arduino 101 device?

This is by design.

Fix the design.

If you explain why that device needs to shut down we might find a solution.

If you don't want to circumvent the primary problem, just flush everything after 8 seconds of running and don't log anything after that. I know that's bad solution but I think you have to fix the design error and not try to implement work-arounds for the implications.