because of timestamp. Arduino crash

If I don't use timestamp in my data string. Then I can run the program without any delay and my sensor testing without the arduino crash continuously. But I place my timestamp string in my datastring, and let my inductive sensor 1 time switching and my program crash. even with a delay(2000).

It is most certainly not necessary to create a huge String to write to the file. You can write one value at a time, followed by writing the field separator.

If you do find it easier to understand what is going on, using sprintf() to populate a char array will use fewer resources than the String object you are using now.

Dynamic String creation consumes a lot of memory, of which your Arduino has very little. Static string manipulation uses the same memory over and over.

I think you are running out of memory.