Log when ESP is being reset

if the reset is happening you are unable to retrieve any information except the reset-reason which is send out to the serial port. The reset reason is sendet prior to the very first line of setup. So you can't write code for it.

Writing to EEPROM very often is wearing out the EEPROM after 100.000 writings it is worn out.

You could use a FRAM-module which has 1.000.000.000.000 10^12 writecycles guaranteed.
or keep your ESP (which one ESP32 or ESP8266 ? )connected to a PC always listening on the serial port and logging what is comming in

or printing and logging serial output in a regular manner while the ESP is running and then see what was the last entry because a reset occurred.

best regards Stefan