Beispiel #1
0
        /// <summary>
        /// Open Log
        /// </summary>
        /// <param name="path"></param>
        /// <param name="name"></param>
        public void Open(string path, string name)
        {
            log_path  = path;
            log_name  = name;
            datafile  = DEFS.LOG_DATA_FILE_NAME(log_path, log_name);
            indexfile = DEFS.LOG_INDEX_FILE_NAME(log_path, log_name);

            //Check if directory exists
            if (System.IO.Directory.Exists(log_path))
            {
                if (System.IO.File.Exists(indexfile))
                {
                    fx     = System.IO.File.OpenRead(indexfile);
                    length = fx.Length / 16;
                    fx.Close();
                }
                else
                {
                    length = 0;
                    fx     = System.IO.File.Open(indexfile, FileMode.Create);
                    fx.Close();
                    fs = System.IO.File.Open(datafile, FileMode.Create);
                    fs.Close();
                }
                _ready = true;
            }
            else
            {
                throw new Exception("Error: Directory is not found - " + log_path);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Archive log
        /// </summary>
        /// <returns></returns>
        public void Archive()
        {
            DateTime d     = DateTime.Now;
            string   s     = d.Year.ToString("d4") + "-" + d.Month.ToString("d2") + "-" + d.Day.ToString("d2") + "_" + d.Hour.ToString("d2") + "-" + d.Minute.ToString("d2") + "-" + d.Second.ToString("d2");
            string   dfile = DEFS.LOG_DATA_FILE_NAME(log_path + "\\arc", log_name, s) + ".bak";
            string   ifile = DEFS.LOG_INDEX_FILE_NAME(log_path + "\\arc", log_name, s) + ".bak";

            System.IO.File.Copy(datafile, dfile, true);
            System.IO.File.Copy(indexfile, ifile, true);

            Purge();
        }