Datalogger adxl377

Hey everyone, Im doing a small datalogger with the adxl377 but when trying to log data to the sd card its no good.
Here is the sketch I`m using any sugestions or help are welcome and thanks

#include <SD.h>


 const int CS = 10;
 File logfile;
 long idd = 0;
 long ids = 0; 
 long idm = 0;
 long idh = 0;
 int set = 1;
 
void error(char *str)
{
  Serial.print("error");
  Serial.println(str);
}

void setup() {
  // open a serial connection
  Serial.begin(115200);
  pinMode(CS, OUTPUT);
  
  if(!SD.begin(CS))
  {
    Serial.println("Card Failure");
    return;
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.TSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
    }
    
    if (logfile) {
   logfile.print("Tiempo");
   logfile.print("\t");
   logfile.print("X");
   logfile.print("\t");
   logfile.print("Y");
   logfile.print("\t");
   logfile.println("Z");
   break;
  } 
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);
}

void loop() {
  
  if (set == 1) {
    ids = ids + 1;
  }
  
  if (ids > 59) {
    ids = 0;
    idm = idm + 1;
  }
  if (idm > 59) {
    idm = 0;
    idh = idh + 1;
  }
  
  logfile.print(idh);
  logfile.print(idm);
  logfile.print(ids);
  logfile.print("\t");
  logfile.print(analogRead(A0));
  logfile.print(analogRead(A1));
  logfile.println(analogRead(A2));
  
  // change the resolution to 16 bits and read A0
  Serial.print("x :");
  Serial.print(analogRead(A0));
  Serial.print("y :");
  Serial.print(analogRead(A1));
  Serial.print("z :");
  Serial.println(analogRead(A2));
  
  delay(1000);
}

The Sd card Initialize ok but no datas transfered to it, the sensor works correctly and via the serial monitor I get data but no logging to the sd card

I find it safest to

open file
create filename
close file

then in the loop

open file
write data
close file

The file is only open when needed and then closed immediately after. In may case the filename is changed at midnight.

I find it safest to

open file
create filename
close file

Open a file first, then define the name of the file to open. Doesn't work for me.

Yes, not too good

determine filename

void createFileName(){
myFile = SD.open(filename, FILE_WRITE);
myFile.close();

then in the loop

open file
write data
close file

I have tryed that allready, in the the loop I open the file, write to it and the put the logfile.close(); but it only write one line of data.

I have tryed that allready, in the the loop I open the file, write to it and the put the logfile.close(); but it only write one line of data.

Not in loop() of the code you posted.

No, not in this one, but I have tryed after logfile.println(analogRead(A0)); puting thee logfile.close(); and the only result was only one line of data logged.