/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="filePath">The complete path of the logfile</param>
 /// <param name="options">Multifile option (e.g. format pattern)</param>
 public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultifileOptions options)
 {
     this.options         = options;
     this.logFileInfo     = logFileInfo;
     this.filenameBuilder = new RolloverFilenameBuilder(this.options.FormatPattern);
     this.filenameBuilder.SetFileName(logFileInfo.FileName);
 }
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="filePath">The complete path of the logfile</param>
		/// <param name="options">Multifile option (e.g. format pattern)</param>
		public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultifileOptions options)
		{
			this.options = options;
			this.logFileInfo = logFileInfo;
			this.filenameBuilder = new RolloverFilenameBuilder(this.options.FormatPattern);
			this.filenameBuilder.SetFileName(logFileInfo.FileName);
		}
Beispiel #3
0
		public LogfileReader(string fileName, EncodingOptions encodingOptions, bool multiFile, int bufferCount, int linesPerBuffer, MultifileOptions mutlifileOptions)
		{
			if (fileName == null)
			{
				return;
			}
			_fileName = fileName;
			EncodingOptions = encodingOptions;
			_isMultiFile = multiFile;
			MAX_BUFFERS = bufferCount;
			MAX_LINES_PER_BUFFER = linesPerBuffer;
			_mutlifileOptions = mutlifileOptions;

			InitLruBuffers();

			if (multiFile)
			{
				ILogFileInfo info = GetLogFileInfo(fileName);
				RolloverFilenameHandler rolloverHandler = new RolloverFilenameHandler(info, _mutlifileOptions);
				LinkedList<string> nameList = rolloverHandler.GetNameList();

				ILogFileInfo fileInfo = null;
				foreach (string name in nameList)
				{
					fileInfo = AddFile(name);
				}
				_watchedILogFileInfo = fileInfo;  // last added file in the list is the watched file
			}
			else
			{
				_watchedILogFileInfo = AddFile(fileName);
			}
			StartGCThread();
		}
 public void testFilenameListWithAppendedIndex()
 {
   MultifileOptions options = new MultifileOptions();
   options.FormatPattern = "*$J(.)";
   options.MaxDayTry = 66;
   LinkedList<string> files = CreateTestfilesWithoutDate();
   string firstFile = files.Last.Value;
   ILogFileInfo info = new LogFileInfo(new Uri(firstFile));
   RolloverFilenameHandler handler = new RolloverFilenameHandler(info, options);
   LinkedList<string> fileList = handler.GetNameList();
   Assert.AreEqual(files, fileList);
   Cleanup();
 }
        public void testFilenameListWithAppendedIndex()
        {
            MultifileOptions options = new MultifileOptions();

            options.FormatPattern = "*$J(.)";
            options.MaxDayTry     = 66;
            LinkedList <string> files         = CreateTestfilesWithoutDate();
            string                  firstFile = files.Last.Value;
            ILogFileInfo            info      = new LogFileInfo(new Uri(firstFile));
            RolloverFilenameHandler handler   = new RolloverFilenameHandler(info, options);
            LinkedList <string>     fileList  = handler.GetNameList();

            Assert.AreEqual(files, fileList);
            Cleanup();
        }
Beispiel #6
0
		public LogfileReader(string[] fileNames, EncodingOptions encodingOptions, int bufferCount, int linesPerBuffer, MultifileOptions mutlifileOptions)
		{
			if (fileNames == null || fileNames.Length < 1)
			{
				return;
			}
			EncodingOptions = encodingOptions;
			_isMultiFile = true;
			MAX_BUFFERS = bufferCount;
			MAX_LINES_PER_BUFFER = linesPerBuffer;
			_mutlifileOptions = mutlifileOptions;

			InitLruBuffers();

			ILogFileInfo fileInfo = null;
			foreach (string name in fileNames)
			{
				fileInfo = AddFile(name);
			}
			_watchedILogFileInfo = fileInfo;
			_fileName = fileInfo.FullName;

			StartGCThread();
		}
Beispiel #7
0
 void SetDefaultsFromPrefs()
 {
     filterTailCheckBox.Checked = Preferences.filterTail;
     syncFilterCheckBox.Checked = Preferences.filterSync;
     FollowTailChanged(Preferences.followTail, false);
     _multifileOptions = ObjectClone.Clone<MultifileOptions>(Preferences.multifileOptions);
 }
Beispiel #8
0
    public void testShiftBuffers1()
    {
      int linesPerFile = 10;
      MultifileOptions options = new MultifileOptions();
      options.MaxDayTry = 0;
      options.FormatPattern = "*$J(.)";
      LinkedList<string> files = CreateTestfilesWithoutDate();
      EncodingOptions encodingOptions = new EncodingOptions();
      encodingOptions.Encoding = Encoding.Default;
      LogfileReader reader = new LogfileReader(files.Last.Value, encodingOptions, true, 40, 50, options);
      reader.ReadFiles();

      IList<ILogFileInfo> lil = reader.GetLogFileInfoList();
      Assert.AreEqual(files.Count, lil.Count);
      LinkedList<string>.Enumerator enumerator = files.GetEnumerator();
      enumerator.MoveNext();
      foreach (LogFileInfo li in lil)
      {
        string fileName = enumerator.Current;
        Assert.AreEqual(fileName, li.FullName);
        enumerator.MoveNext();
      }
      int oldCount = lil.Count;

      // Simulate rollover
      //
      files = RolloverSimulation(files, "*$J(.)", false);

      // Simulate rollover detection 
      //
      reader.ShiftBuffers();

      lil = reader.GetLogFileInfoList();
      Assert.AreEqual(oldCount + 1, lil.Count);

      Assert.AreEqual(linesPerFile * lil.Count, reader.LineCount);

      // Check if rollover'd file names have been handled by LogfileReader
      //
      Assert.AreEqual(files.Count, lil.Count);
      enumerator = files.GetEnumerator();
      enumerator.MoveNext();
      foreach (LogFileInfo li in lil)
      {
        string fileName = enumerator.Current;
        Assert.AreEqual(fileName, li.FullName);
        enumerator.MoveNext();
      }

      // Check if file buffers have correct files. Assuming here that one buffer fits for a 
      // complete file
      //
      enumerator = files.GetEnumerator();
      enumerator.MoveNext();
      IList<LogBuffer> logBuffers = reader.GetBufferList();
      int startLine = 0;
      foreach (LogBuffer logBuffer in logBuffers)
      {
        Assert.AreEqual(logBuffer.FileInfo.FullName, enumerator.Current);
        Assert.AreEqual(startLine, logBuffer.StartLine);
        startLine += 10;
        enumerator.MoveNext();
      }

      // Checking file content
      //
      enumerator = files.GetEnumerator();
      enumerator.MoveNext();
      enumerator.MoveNext();  // move to 2nd entry. The first file now contains 2nd file's content (because rollover)
      logBuffers = reader.GetBufferList();
      int i;
      for (i = 0; i < logBuffers.Count - 2; ++i)
      {
        LogBuffer logBuffer = logBuffers[i];
        string line = logBuffer.GetLineOfBlock(0);
        Assert.IsTrue(line.Contains(enumerator.Current));
        enumerator.MoveNext();
      }
      enumerator.MoveNext();
      // the last 2 files now contain the content of the previously watched file
      for (; i < logBuffers.Count; ++i)
      {
        LogBuffer logBuffer = logBuffers[i];
        string line = logBuffer.GetLineOfBlock(0);
        Assert.IsTrue(line.Contains(enumerator.Current));
      }

      oldCount = lil.Count;

      // Simulate rollover again - now latest file will be deleted (simulates logger's rollover history limit)
      //
      files = RolloverSimulation(files, "*$J(.)", true);

      // Simulate rollover detection 
      //
      reader.ShiftBuffers();
      lil = reader.GetLogFileInfoList();

      Assert.AreEqual(oldCount, lil.Count);    // same count because oldest file is deleted
      Assert.AreEqual(files.Count, lil.Count);
      Assert.AreEqual(linesPerFile * lil.Count, reader.LineCount);

      // Check first line to see if buffers are correct
      //
      string firstLine = reader.GetLogLine(0);
      string[] names = new string[files.Count];
      files.CopyTo(names, 0);
      Assert.IsTrue(firstLine.Contains(names[2]));
    }