Beispiel #1
0
		internal string[] GetColumnsForLine(LogfileReader logFileReader, int lineNumber, ILogLineColumnizer columnizer, LogExpert.ColumnizerCallback columnizerCallback)
		{
			if (_lastColumnizer != columnizer || _lastLineNumber != lineNumber || _cachedColumns == null || columnizerCallback.LineNum != lineNumber)
			{
				_lastColumnizer = columnizer;
				_lastLineNumber = lineNumber;
				string line = logFileReader.GetLogLineWithWait(lineNumber);
				if (line != null)
				{
					columnizerCallback.LineNum = lineNumber;
					_cachedColumns = columnizer.SplitLine(columnizerCallback, line);
				}
				else
				{
					_cachedColumns = null;
				}
			}

			return _cachedColumns;
		}
Beispiel #2
0
        private void LoadFilesAsMultiInternal(string[] fileNames, EncodingOptions encodingOptions)
        {
            Logger.logInfo("Loading given files as MultiFile:");

            EnterLoadFileStatus();

            foreach (string name in fileNames)
            {
                Logger.logInfo("File: " + name);
            }

            if (CurrentLogFileReader != null)
            {
                CurrentLogFileReader.stopMonitoring();
                UnRegisterLogFileReaderEvents();
            }

            EncodingOptions = encodingOptions;
            _columnCache = new ColumnCache();

            CurrentLogFileReader = new LogfileReader(
                fileNames,
                EncodingOptions,
                Preferences.bufferCount,
                Preferences.linesPerBuffer,
                _multifileOptions);

            CurrentLogFileReader.UseNewReader = !Preferences.useLegacyReader;
            RegisterLogFileReaderEvents();
            CurrentLogFileReader.startMonitoring();
            FileName = fileNames[fileNames.Length - 1];
            _fileNames = fileNames;
            IsMultiFile = true;
        }
Beispiel #3
0
        private void LoadFileInternal(string fileName, EncodingOptions encodingOptions)
        {
            EnterLoadFileStatus();

            if (fileName != null)
            {
                FileName = fileName;
                EncodingOptions = encodingOptions;

                if (CurrentLogFileReader != null)
                {
                    CurrentLogFileReader.StopMonitoringAsync();
                    UnRegisterLogFileReaderEvents();
                }
                if (!LoadPersistenceOptions())
                {
                    if (!IsTempFile)
                    {
                        ILogLineColumnizer columnizer = FindColumnizer();
                        if (columnizer != null)
                        {
                            if (_reloadMemento == null)
                            {
                                columnizer = Util.CloneColumnizer(columnizer);
                            }
                        }
                        PreSelectColumnizer(columnizer);
                    }
                    SetDefaultHighlightGroup();
                }

                // this may be set after loading persistence data
                if (_fileNames != null && IsMultiFile)
                {
                    LoadFilesAsMulti(_fileNames, EncodingOptions);
                    return;
                }
                _columnCache = new ColumnCache();
                try
                {
                    CurrentLogFileReader = new LogfileReader(
                        fileName,
                        EncodingOptions,
                        IsMultiFile,
                        Preferences.bufferCount,
                        Preferences.linesPerBuffer,
                        _multifileOptions);
                    CurrentLogFileReader.UseNewReader = !Preferences.useLegacyReader;
                }
                catch (LogFileException lfe)
                {
                    MessageBox.Show("Cannot load file\n" + lfe.Message, "LogExpert");
                    BeginInvoke(new Action<bool>(Close), new object[] { true });
                    _isLoadError = true;
                    return;
                }

                ILogLineXmlColumnizer xmlColumnizer = CurrentColumnizer as ILogLineXmlColumnizer;

                if (xmlColumnizer != null)
                {
                    CurrentLogFileReader.IsXmlMode = true;
                    CurrentLogFileReader.XmlLogConfig = xmlColumnizer.GetXmlLogConfiguration();
                }

                if (_forcedColumnizerForLoading != null)
                {
                    CurrentColumnizer = _forcedColumnizerForLoading;
                }

                IPreProcessColumnizer preProcessColumnizer = CurrentColumnizer as IPreProcessColumnizer;

                if (CurrentColumnizer is IPreProcessColumnizer)
                {
                    CurrentLogFileReader.PreProcessColumnizer = preProcessColumnizer;
                }
                else
                {
                    CurrentLogFileReader.PreProcessColumnizer = null;
                }

                RegisterLogFileReaderEvents();
                Logger.logInfo("Loading logfile: " + fileName);
                CurrentLogFileReader.startMonitoring();
            }
        }
Beispiel #4
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]));
    }