Serial.write clears array

Hi,
I tried to, but I don't understand:
My program reads the analog input into an array.

If I start the serial Monitor after some probes were stored, all array contend and the countlog are initialized with zero.
I want to read the array at least only one time a day.

Why? What keyword I have to search for?

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int toggle=HIGH;
int datlog[10];
int countlog=0;

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  
}

void read_datlog()
{
 int i;
 Serial.begin(9600);
 //if (Serial.available())
 //{
 for ( i=0;i<countlog;i++)
 {
   Serial.print(i, DEC);
   Serial.print(";");    
   Serial.print(datlog[i], DEC);
   Serial.println() ; 
     
 }
 //}
 Serial.end();
}
void loop() {
  static int count10=0;
  static int sum=0;
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);     
  // turn the ledPin on
  digitalWrite(ledPin, toggle);  
       if (toggle==HIGH)
          toggle=LOW;
       else
          toggle=HIGH;
   
  //delay(sensorValue);    
  count10++;
  sum=sum+sensorValue;
  if (count10>=10)
  {
     datlog[countlog++]=sum/10;
     count10=0;
     sum=0;
     //if (countlog%2==0)
     read_datlog();

  }
  delay(6000);

}

Restarting the serial monitor resets the Arduino. Hence what you see. There are ways around it. Try searching for "reset" and "serial monitor". For one thing, cutting a trace on the board will do it. Also I think you can configure the serial port to not do a "hangup" (or whatever it is) that causes the reset.

Hi Nick,
yes you're so right.
I got it managed; I chose the way with a capacitor.

Thanks.
Carsten