/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/Program.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/17 10:34:06	240
+++ trunk/GBPVRProgramDatabaseFixer/Program.cs	2013/03/17 10:40:09	241
@@ -16,6 +16,35 @@
 {
     class Program
     {
+        const long MAX_LOG_FILESIZE_IN_BYTES = 250000; //250kb max
+        static void TruncateLogFile(FileInfo log_file)
+        {
+            if (!log_file.Exists)
+            {
+                gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All);
+            }
+            else
+            {
+                if (log_file.Length > MAX_LOG_FILESIZE_IN_BYTES)
+                {
+                    string match = string.Format("{0}.*", log_file.Name);
+                    var files = Directory.GetFiles(log_file.Directory.FullName, match).ToList();
+                    files.RemoveAt(0);
+                    files.TrimExcess();
+                    int count = files.Count;
+                    if (log_file.Exists)
+                    {
+                        File.Copy(log_file.FullName, string.Format("{0}.{1}", log_file.FullName, count));
+                    }
+                    gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All);
+                }
+                else
+                {
+                    gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All);
+                }
+            }
+        }
+
         static ISQLLITE sqlite;
         static string XMLTV_FILE = "";
         static string GBPVR_DATABASE = "";
@@ -37,7 +66,8 @@
         {
             string log_path = Application.StartupPath;
             string log_filename = string.Format("{0}.log", typeof(Program).Assembly.GetName().Name);
-            gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All);
+            FileInfo log_file = new FileInfo(string.Format(@"{0}\{1}", log_path, log_filename));
+            TruncateLogFile(log_file);
 #if DEBUG
             LogLevel gLevel = gLog.LogLevel;
             gLevel |= LogLevel.kLogLevel_VerboseDebug;

 

  ViewVC Help
Powered by ViewVC 1.1.22