コード例 #1
0
ファイル: RollingNameTest.cs プロジェクト: gspatace/logexpert
 public void testFilename3()
 {
   RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("*_$I.log");
   fnb.SetFileName("engine_0.log");
   string name = fnb.BuildFileName();
   Assert.AreEqual("engine_0.log", name);
   fnb.Index = fnb.Index + 1;
   name = fnb.BuildFileName();
   Assert.AreEqual("engine_1.log", name);
 }
コード例 #2
0
ファイル: RollingNameTest.cs プロジェクト: gspatace/logexpert
 public void testFilename2()
 {
   RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("*$D(yyyy-MM-dd).log");
   fnb.SetFileName("engine_2010-06-12.log");
   string name = fnb.BuildFileName();
   Assert.AreEqual("engine_2010-06-12.log", name);
   fnb.Index = fnb.Index + 1;
   name = fnb.BuildFileName();
   Assert.AreEqual("engine_2010-06-12.log", name);
 }
コード例 #3
0
        public void testFilenameHiddenZero3()
        {
            RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("engine$J.log");

            fnb.SetFileName("engine1.log");
            string name = fnb.BuildFileName();

            Assert.AreEqual("engine1.log", name);
            fnb.Index = fnb.Index - 1;
            name      = fnb.BuildFileName();
            Assert.AreEqual("engine.log", name);
        }
コード例 #4
0
        public void testFilename3()
        {
            RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("*_$I.log");

            fnb.SetFileName("engine_0.log");
            string name = fnb.BuildFileName();

            Assert.AreEqual("engine_0.log", name);
            fnb.Index = fnb.Index + 1;
            name      = fnb.BuildFileName();
            Assert.AreEqual("engine_1.log", name);
        }
コード例 #5
0
        public void testFilename2()
        {
            RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("*$D(yyyy-MM-dd).log");

            fnb.SetFileName("engine_2010-06-12.log");
            string name = fnb.BuildFileName();

            Assert.AreEqual("engine_2010-06-12.log", name);
            fnb.Index = fnb.Index + 1;
            name      = fnb.BuildFileName();
            Assert.AreEqual("engine_2010-06-12.log", name);
        }
コード例 #6
0
ファイル: RollingNameTest.cs プロジェクト: gspatace/logexpert
 public void testFilenameHiddenZero2()
 {
   RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("engine$J.log");
   fnb.SetFileName("engine.log");
   string name = fnb.BuildFileName();
   Assert.AreEqual("engine.log", name);
   fnb.Index = fnb.Index + 1;
   name = fnb.BuildFileName();
   Assert.AreEqual("engine1.log", name);
   fnb.Index = fnb.Index + 1;
   name = fnb.BuildFileName();
   Assert.AreEqual("engine2.log", name);
 }
コード例 #7
0
        /// <summary>
        /// Returns a list of the built file names (complete path) which also exists on disk.
        /// The list is created by using the RolloverFilenameBuilder and checking for file existence.
        /// The first entry in the list contains the oldest file. The last entry contains the file given
        /// in the contructor.
        /// </summary>
        /// <returns></returns>
        public LinkedList <string> GetNameList()
        {
            LinkedList <string> fileList = new LinkedList <string>();
            string fileName = filenameBuilder.BuildFileName();
            string filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;

            fileList.AddFirst(filePath);
            bool found = true;

            while (found)
            {
                found = false;
                // increment index and check if file exists
                if (this.filenameBuilder.IsIndexPattern)
                {
                    this.filenameBuilder.Index = this.filenameBuilder.Index + 1;
                    fileName = filenameBuilder.BuildFileName();
                    filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;
                    if (FileExists(filePath))
                    {
                        fileList.AddFirst(filePath);
                        found = true;
                        continue;
                    }
                }
                // if file with index isn't found or no index is in format pattern, decrement the current date
                if (this.filenameBuilder.IsDatePattern)
                {
                    int tryCounter = 0;
                    this.filenameBuilder.Index = 0;
                    while (tryCounter < this.options.MaxDayTry)
                    {
                        this.filenameBuilder.DecrementDate();
                        fileName = filenameBuilder.BuildFileName();
                        filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;
                        if (FileExists(filePath))
                        {
                            fileList.AddFirst(filePath);
                            found = true;
                            break;
                        }
                        else
                        {
                            tryCounter++;
                        }
                    }
                }
            }
            return(fileList);
        }
コード例 #8
0
        public void testFilenameHiddenZero()
        {
            RolloverFilenameBuilder fnb = new RolloverFilenameBuilder("*.log$J(.)");

            fnb.SetFileName("engine.log");
            string name = fnb.BuildFileName();

            Assert.AreEqual("engine.log", name);
            fnb.Index = fnb.Index + 1;
            name      = fnb.BuildFileName();
            Assert.AreEqual("engine.log.1", name);
            fnb.Index = fnb.Index + 1;
            name      = fnb.BuildFileName();
            Assert.AreEqual("engine.log.2", name);
        }
コード例 #9
0
        protected LinkedList <string> RolloverSimulation(LinkedList <string> files, string formatPattern, bool deleteLatestFile)
        {
            LinkedList <string>     fileList = files;
            RolloverFilenameBuilder fnb      = new RolloverFilenameBuilder(formatPattern);

            fnb.SetFileName(fileList.Last.Value);
            fnb.Index = fnb.Index + fileList.Count;
            string newFileName = fnb.BuildFileName();

            fileList.AddFirst(newFileName);
            LinkedList <string> .Enumerator enumerator     = fileList.GetEnumerator();
            LinkedList <string> .Enumerator nextEnumerator = fileList.GetEnumerator();
            nextEnumerator.MoveNext(); // move on 2nd entry
            enumerator.MoveNext();
            while (nextEnumerator.MoveNext())
            {
                File.Move(nextEnumerator.Current, enumerator.Current);
                enumerator.MoveNext();
            }
            CreateFile(null, nextEnumerator.Current);
            if (deleteLatestFile)
            {
                File.Delete(fileList.First.Value);
                fileList.RemoveFirst();
            }
            return(fileList);
        }
コード例 #10
0
 protected LinkedList<string> RolloverSimulation(LinkedList<string> files, string formatPattern, bool deleteLatestFile)
 {
   LinkedList<string> fileList = files;
   RolloverFilenameBuilder fnb = new RolloverFilenameBuilder(formatPattern);
   fnb.SetFileName(fileList.Last.Value);
   fnb.Index = fnb.Index + fileList.Count;
   string newFileName = fnb.BuildFileName();
   fileList.AddFirst(newFileName);
   LinkedList<string>.Enumerator enumerator = fileList.GetEnumerator();
   LinkedList<string>.Enumerator nextEnumerator = fileList.GetEnumerator();
   nextEnumerator.MoveNext();    // move on 2nd entry
   enumerator.MoveNext();
   while (nextEnumerator.MoveNext())
   {
     File.Move(nextEnumerator.Current, enumerator.Current);
     enumerator.MoveNext();
   }
   CreateFile(null, nextEnumerator.Current);
   if (deleteLatestFile)
   {
     File.Delete(fileList.First.Value);
     fileList.RemoveFirst();
   }
   return fileList;
 }