Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 12537)
+++ /trunk/FACT++/src/datalogger.cc	(revision 12538)
@@ -389,4 +389,5 @@
     //Current day variable. Used to close nightly files when night changes
     int fCurrentDay;
+    Time lastFlush;
 public:
     int Write(const Time &time, const std::string &txt, int qos=kMessage);
@@ -759,4 +760,5 @@
     const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
     fCurrentDay = nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
+    lastFlush = Time();
 
     //Give a name to this machine's specific states
@@ -1178,4 +1180,22 @@
     int newDayNumber = nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
 
+    //also check if we should flush the nightly files
+    if (lastFlush < timeNow-boost::posix_time::minutes(1))
+    {
+        lastFlush = timeNow;
+        SubscriptionsListType::iterator x;
+        map<string, SubscriptionType>::iterator y;
+        for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++)
+        {//find current service is subscriptions
+            for (y=x->second.begin(); y!=x->second.end();y++)
+                if (y->second.nightlyFile.IsOpen())
+                {
+                    y->second.nightlyFile.Flush();
+                }
+        }
+        if (fDebugIsOn)
+            Debug("Just flushed nightly fits files to the disk");
+    }
+
 //    if (Time().h() == 12 && !fDailyFileDayChangedAlready)
     if (newDayNumber !=  fCurrentDay)
@@ -1905,5 +1925,5 @@
                 return;
             }
-            sub.nightlyFile.Flush();
+ //           sub.nightlyFile.Flush();
          }
 
