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(); }
private string BuildWatermarkFileInfo(ILogFileInfo logFileInfo) { string watermarkFileFullName = logFileInfo.WatermarkFileObj.WatermarkFileFullName; string result = string.Empty; try { FileInfo fileInfo = new FileInfo(watermarkFileFullName); if (fileInfo.Exists) { result = string.Format("the watermark file={0},created={1},modified={2}", watermarkFileFullName, fileInfo.CreationTimeUtc, fileInfo.LastWriteTimeUtc); } else { result = string.Format("the watermark file {0} doesn't exist", watermarkFileFullName); } } catch (Exception ex) { if (RetryHelper.IsSystemFatal(ex)) { throw; } result = string.Format("the watermark file {0} exists but can't retrive its info because of exception: {1}", watermarkFileFullName, ex.Message); } return(result); }
private void ToolButtonClick(ToolEntry toolEntry) { if (string.IsNullOrEmpty(toolEntry.cmd)) { //TODO TabIndex => To Enum OpenSettings(2); return; } if (CurrentLogWindow != null) { ILogLine line = CurrentLogWindow.GetCurrentLine(); ILogFileInfo info = CurrentLogWindow.GetCurrentFileInfo(); if (line != null && info != null) { ArgParser parser = new ArgParser(toolEntry.args); string argLine = parser.BuildArgs(line, CurrentLogWindow.GetRealLineNum() + 1, info, this); if (argLine != null) { StartTool(toolEntry.cmd, argLine, toolEntry.sysout, toolEntry.columnizerName, toolEntry.workingDir); } } } }
private bool FileExists(string filePath) { IFileSystemPlugin fs = PluginRegistry.GetInstance().FindFileSystemForUri(filePath); ILogFileInfo info = fs.GetLogfileInfo(filePath); return(info.FileExists); }
/// <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); }
/// <summary> /// Constructor. /// </summary> /// <param name="logFileInfo">The complete path of the logfile</param> /// <param name="options">Multifile option (e.g. format pattern)</param> public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultiFileOptions options) { _options = options; _logFileInfo = logFileInfo; _filenameBuilder = new RolloverFilenameBuilder(_options.FormatPattern); _filenameBuilder.SetFileName(logFileInfo.FileName); }
protected void UpdateStaleLogs(ILogFileInfo logFileInfo) { double totalHours = DateTime.UtcNow.Subtract(logFileInfo.LastWriteTimeUtc).TotalHours; if (!this.IsFileProcessedBefore(logFileInfo) && !LogMonitor <T> .IsEmptyLog(logFileInfo) && totalHours >= this.config.BacklogAlertNonUrgentThreshold.TotalHours) { this.staleLogs.Add(logFileInfo); if (totalHours >= this.config.BacklogAlertUrgentThreshold.TotalHours) { this.veryStaleLogs.Add(logFileInfo); } } }
private void testButton_Click(object sender, EventArgs e) { if (this.logTabWin.CurrentLogWindow != null) { string line = this.logTabWin.CurrentLogWindow.GetCurrentLine(); ILogFileInfo info = this.logTabWin.CurrentLogWindow.GetCurrentFileInfo(); if (line != null && info != null) { ArgParser parser = new ArgParser(this.argsTextBox.Text); string args = parser.BuildArgs(line, this.logTabWin.CurrentLogWindow.GetRealLineNum() + 1, info, this); this.testResultLabel.Text = args; } } }
public InputBuffer(int batchSizeInBytes, long beginOffset, ILogFileInfo logFileInfoObj, ThreadSafeQueue <T> logDataBatchQueue, string prefix, ILogMonitorHelper <T> logMonitorHelper, int messageBatchFlushInterval, CancellationContext cancelContext, int maxBatchCount, string instanceName = null) { if (batchSizeInBytes <= 0) { throw new ArgumentOutOfRangeException("batchSizeInByte", "The batch size should be greater than 0."); } if (beginOffset < 0L) { throw new ArgumentOutOfRangeException("beginOffset", "The beginOffset should be equal or greater than 0."); } if (logDataBatchQueue == null) { throw new ArgumentNullException("logDataBatchQueue cannot be null."); } if (messageBatchFlushInterval < 0) { throw new ArgumentOutOfRangeException("messageBatchFlushInterval", "The messageBatchFlushInterval must not be a negative number."); } ArgumentValidator.ThrowIfNull("logFileInfoObj", logFileInfoObj); ArgumentValidator.ThrowIfNull("watermarkFileRef", logFileInfoObj.WatermarkFileObj); if (string.IsNullOrEmpty(logFileInfoObj.FullFileName)) { throw new ArgumentException("fullLogName cannot be null or emtpy."); } ArgumentValidator.ThrowIfNull("cancelContext", cancelContext); this.cancellationContext = cancelContext; this.messageBatchFlushInterval = messageBatchFlushInterval; this.batchSizeInBytes = batchSizeInBytes; this.logDataBatchQueue = logDataBatchQueue; this.watermarkFileRef = logFileInfoObj.WatermarkFileObj; this.maximumBatchCount = ((maxBatchCount <= 0) ? int.MaxValue : maxBatchCount); this.lastFluchCheckTime = DateTime.UtcNow; this.logMonitorHelper = logMonitorHelper; this.fullLogName = logFileInfoObj.FullFileName; this.instance = (string.IsNullOrEmpty(instanceName) ? prefix : instanceName); this.logPrefix = prefix; this.perfCounterInstance = PerfCountersInstanceCache.GetInstance(this.instance); this.shouldBufferBatches = this.ShouldBufferBatches(); this.CreateNewBatch(beginOffset); if (this.shouldBufferBatches) { MessageBatchBase messageBatchBase = this.activeBatch as MessageBatchBase; if (messageBatchBase != null) { messageBatchBase.MessageBatchFlushInterval = this.messageBatchFlushInterval; } } }
public void testUriToFileStream() { DirectoryInfo dInfo = Directory.CreateDirectory(RolloverHandlerTest.TEST_DIR_NAME); string fullName = CreateFile(dInfo, "test.log"); LocalFileSystem fs = new LocalFileSystem(); ILogFileInfo info = fs.GetLogfileInfo(fullName); Assert.True(info.Length > 0); Assert.True(info.OriginalLength == info.Length); Stream stream = info.OpenStream(); Assert.True(stream.CanSeek); StreamReader reader = new StreamReader(stream); string line = reader.ReadLine(); Assert.True(line.StartsWith("line number", StringComparison.InvariantCultureIgnoreCase)); reader.Close(); }
/// <summary> /// Public for unit test reasons /// </summary> public void ReadFiles() { _currFileSize = 0; LineCount = 0; //lastReturnedLine = ""; //lastReturnedLineNum = -1; //lastReturnedLineNumForBuffer = -1; _isDeleted = false; ClearLru(); AcquireBufferListWriterLock(); _bufferList.Clear(); ReleaseBufferListWriterLock(); try { foreach (ILogFileInfo info in _logFileInfoList) { //info.OpenFile(); ReadToBufferList(info, 0, LineCount); } if (_logFileInfoList.Count > 0) { ILogFileInfo info = _logFileInfoList[_logFileInfoList.Count - 1]; _fileLength = info.Length; _watchedILogFileInfo = info; } } catch (IOException e) { Logger.logWarn(string.Format("IOException: {0}", e.Message)); _fileLength = 0; _isDeleted = true; LineCount = 0; } LogEventArgs args = new LogEventArgs(); args.PrevFileSize = 0; args.PrevLineCount = 0; args.LineCount = LineCount; args.FileSize = _currFileSize; OnFileSizeChanged(args); }
internal bool IsFileProcessedBefore(ILogFileInfo logFileInfo) { string watermarkFileFullName = logFileInfo.WatermarkFileObj.WatermarkFileFullName; return(File.Exists(watermarkFileFullName) || (logFileInfo.Status != ProcessingStatus.NeedProcessing && logFileInfo.Status != ProcessingStatus.Unknown)); }
private void ReplaceBufferInfos(ILogFileInfo oldLogFileInfo, ILogFileInfo newLogFileInfo) { Logger.logDebug(string.Format("ReplaceBufferInfos() {0} -> {1}", oldLogFileInfo.FullName, newLogFileInfo.FullName)); AcquireBufferListReaderLock(); foreach (LogBuffer buffer in _bufferList) { if (buffer.FileInfo == oldLogFileInfo) { Logger.logDebug(string.Format("Buffer with startLine={0}, lineCount={1}, filePos={2}, size={3} gets new filename {4}", buffer.StartLine, buffer.LineCount, buffer.StartPos, buffer.Size, newLogFileInfo.FullName)); buffer.FileInfo = newLogFileInfo; } } ReleaseBufferListReaderLock(); }
/// <summary> /// Public for unit tests. /// </summary> /// <returns></returns> public int ShiftBuffers() { Logger.logInfo(string.Format("ShiftBuffers() begin for {0}{1}", _fileName, IsMultiFile ? " (MultiFile)" : "")); AcquireBufferListWriterLock(); int offset = 0; _isLineCountDirty = true; lock (monitor) { RolloverFilenameHandler rolloverHandler = new RolloverFilenameHandler(_watchedILogFileInfo, _mutlifileOptions); LinkedList<string> fileNameList = rolloverHandler.GetNameList(); ResetBufferCache(); IList<ILogFileInfo> lostILogFileInfoList = new List<ILogFileInfo>(); IList<ILogFileInfo> readNewILogFileInfoList = new List<ILogFileInfo>(); IList<ILogFileInfo> newFileInfoList = new List<ILogFileInfo>(); IEnumerator<ILogFileInfo> enumerator = _logFileInfoList.GetEnumerator(); while (enumerator.MoveNext()) { ILogFileInfo logFileInfo = enumerator.Current; string fileName = logFileInfo.FullName; Logger.logDebug(string.Format("Testing file {0}", fileName)); LinkedListNode<string> node = fileNameList.Find(fileName); if (node == null) { Logger.logWarn(string.Format("File {0} not found", fileName)); continue; } if (node.Previous != null) { fileName = node.Previous.Value; ILogFileInfo newILogFileInfo = GetLogFileInfo(fileName); Logger.logDebug(string.Format("{0} exists", fileName)); Logger.logDebug(string.Format("Old size={0}, new size={1}", logFileInfo.OriginalLength, newILogFileInfo.Length)); // is the new file the same as the old buffer info? if (newILogFileInfo.Length == logFileInfo.OriginalLength) { ReplaceBufferInfos(logFileInfo, newILogFileInfo); newFileInfoList.Add(newILogFileInfo); } else { Logger.logDebug(string.Format("Buffer for {0} must be re-read.", fileName)); // not the same. so must read the rest of the list anew from the files readNewILogFileInfoList.Add(newILogFileInfo); while (enumerator.MoveNext()) { fileName = enumerator.Current.FullName; node = fileNameList.Find(fileName); if (node == null) { Logger.logWarn(string.Format("File {0} not found", fileName)); continue; } if (node.Previous != null) { fileName = node.Previous.Value; Logger.logDebug(string.Format("New name is {0}", fileName)); readNewILogFileInfoList.Add(GetLogFileInfo(fileName)); } else { Logger.logWarn(string.Format("No previous file for {0} found", fileName)); } } } } else { Logger.logInfo(string.Format("{0} does not exist", fileName)); lostILogFileInfoList.Add(logFileInfo); #if DEBUG // for better overview in logfile: //ILogFileInfo newILogFileInfo = new ILogFileInfo(fileName); //ReplaceBufferInfos(ILogFileInfo, newILogFileInfo); #endif } } if (lostILogFileInfoList.Count > 0) { Logger.logInfo("Deleting buffers for lost files"); foreach (ILogFileInfo ILogFileInfo in lostILogFileInfoList) { //ILogFileInfoList.Remove(ILogFileInfo); LogBuffer lastBuffer = DeleteBuffersForInfo(ILogFileInfo, false); if (lastBuffer != null) { offset += lastBuffer.StartLine + lastBuffer.LineCount; } } _lruCacheDictLock.AcquireWriterLock(Timeout.Infinite); Logger.logInfo(string.Format("Adjusting StartLine values in {0} buffers by offset {1}", _bufferList.Count, offset)); foreach (LogBuffer buffer in _bufferList) { SetNewStartLineForBuffer(buffer, buffer.StartLine - offset); } _lruCacheDictLock.ReleaseWriterLock(); #if DEBUG if (_bufferList.Count > 0) { Logger.logInfo(string.Format("First buffer now has StartLine {0}", _bufferList[0].StartLine)); } #endif } // Read anew all buffers following a buffer info that couldn't be matched with the corresponding existing file Logger.logInfo("Deleting buffers for files that must be re-read"); foreach (ILogFileInfo ILogFileInfo in readNewILogFileInfoList) { DeleteBuffersForInfo(ILogFileInfo, true); //ILogFileInfoList.Remove(ILogFileInfo); } Logger.logInfo("Deleting buffers for the watched file"); DeleteBuffersForInfo(_watchedILogFileInfo, true); int startLine = LineCount - 1; Logger.logInfo("Re-Reading files"); foreach (ILogFileInfo ILogFileInfo in readNewILogFileInfoList) { //ILogFileInfo.OpenFile(); ReadToBufferList(ILogFileInfo, 0, LineCount); //ILogFileInfoList.Add(ILogFileInfo); newFileInfoList.Add(ILogFileInfo); } //watchedILogFileInfo = ILogFileInfoList[ILogFileInfoList.Count - 1]; _logFileInfoList = newFileInfoList; _watchedILogFileInfo = GetLogFileInfo(_watchedILogFileInfo.FullName); _logFileInfoList.Add(_watchedILogFileInfo); Logger.logInfo("Reading watched file"); ReadToBufferList(_watchedILogFileInfo, 0, LineCount); } Logger.logInfo(string.Format("ShiftBuffers() end. offset={0}", offset)); ReleaseBufferListWriterLock(); return offset; }
private void ReadToBufferList(ILogFileInfo logFileInfo, long filePos, int startLine) { #if DEBUG //Logger.logDebug("ReadToBufferList(): " + ILogFileInfo.FileName + ", filePos " + filePos + ", startLine: " + startLine); #endif Stream fileStream; ILogStreamReader reader = null; try { fileStream = logFileInfo.OpenStream(); bool canSeek = fileStream.CanSeek; } catch (IOException fe) { Logger.logWarn(string.Format("IOException: {0}", fe.ToString())); _isDeleted = true; LineCount = 0; _currFileSize = 0; OnFileNotFound(); // notify LogWindow return; } try { reader = GetLogStreamReader(fileStream, EncodingOptions, UseNewReader); reader.Position = filePos; _fileLength = logFileInfo.Length; String line; int lineNum = startLine; LogBuffer logBuffer; AcquireBufferListReaderLock(); if (_bufferList.Count == 0) { logBuffer = new LogBuffer(logFileInfo, MAX_LINES_PER_BUFFER); logBuffer.StartLine = startLine; logBuffer.StartPos = filePos; LockCookie cookie = UpgradeBufferListLockToWriter(); AddBufferToList(logBuffer); DowngradeBufferListLockFromWriter(ref cookie); #if DEBUG //Logger.logDebug("ReadToBufferList(): new buffer created"); #endif } else { logBuffer = _bufferList[_bufferList.Count - 1]; //if (logBuffer.FileInfo != ILogFileInfo) if (!logBuffer.FileInfo.FullName.Equals(logFileInfo.FullName)) { logBuffer = new LogBuffer(logFileInfo, MAX_LINES_PER_BUFFER); logBuffer.StartLine = startLine; logBuffer.StartPos = filePos; LockCookie cookie = UpgradeBufferListLockToWriter(); AddBufferToList(logBuffer); DowngradeBufferListLockFromWriter(ref cookie); #if DEBUG //Logger.logDebug("ReadToBufferList(): new buffer created because new ILogFileInfo"); #endif } _disposeLock.AcquireReaderLock(Timeout.Infinite); if (logBuffer.IsDisposed) { LockCookie cookie = _disposeLock.UpgradeToWriterLock(Timeout.Infinite); ReReadBuffer(logBuffer); _disposeLock.DowngradeFromWriterLock(ref cookie); } _disposeLock.ReleaseReaderLock(); } Monitor.Enter(logBuffer); // Lock the buffer ReleaseBufferListReaderLock(); int lineCount = logBuffer.LineCount; int droppedLines = logBuffer.PrevBuffersDroppedLinesSum; filePos = reader.Position; while (ReadLine(reader, logBuffer.StartLine + logBuffer.LineCount, logBuffer.StartLine + logBuffer.LineCount + droppedLines, out line)) { if (_shouldStop) { Monitor.Exit(logBuffer); return; } if (line == null) { logBuffer.DroppedLinesCount = logBuffer.DroppedLinesCount + 1; droppedLines++; continue; } lineCount++; if (lineCount > MAX_LINES_PER_BUFFER && reader.IsBufferComplete) { OnLoadFile(new LoadFileEventArgs(logFileInfo.FullName, filePos, false, logFileInfo.Length, false)); #if DEBUG //Logger.logDebug("ReadToBufferList(): new buffer created. lineCount: " + lineCount + ", lineNum:" + lineNum + ", text: " + line); #endif //logBuffer.Size = filePos - logBuffer.StartPos; Monitor.Exit(logBuffer); logBuffer = new LogBuffer(logFileInfo, MAX_LINES_PER_BUFFER); Monitor.Enter(logBuffer); logBuffer.StartLine = lineNum; logBuffer.StartPos = filePos; logBuffer.PrevBuffersDroppedLinesSum = droppedLines; AcquireBufferListWriterLock(); AddBufferToList(logBuffer); ReleaseBufferListWriterLock(); lineCount = 1; } logBuffer.AddLine(line, filePos); filePos = reader.Position; lineNum++; } logBuffer.Size = filePos - logBuffer.StartPos; Monitor.Exit(logBuffer); _isLineCountDirty = true; _currFileSize = reader.Position; CurrentEncoding = reader.Encoding; // Reader may have detected another encoding if (!_shouldStop) { OnLoadFile(new LoadFileEventArgs(logFileInfo.FullName, filePos, true, _fileLength, false)); // Fire "Ready" Event } GC.KeepAlive(fileStream); } catch (IOException ioex) { Logger.logWarn(string.Format("{0}: {1}", ioex.GetType().Name, ioex.Message)); } finally { fileStream.Close(); } }
private LogBuffer DeleteBuffersForInfo(ILogFileInfo ILogFileInfo, bool matchNamesOnly) { Logger.logInfo(string.Format("Deleting buffers for file {0}", ILogFileInfo.FullName)); LogBuffer lastRemovedBuffer = null; IList<LogBuffer> deleteList = new List<LogBuffer>(); AcquireBufferListWriterLock(); _lruCacheDictLock.AcquireWriterLock(Timeout.Infinite); if (matchNamesOnly) { foreach (LogBuffer buffer in _bufferList) { if (buffer.FileInfo.FullName.ToLower().Equals(ILogFileInfo.FullName.ToLower())) { lastRemovedBuffer = buffer; deleteList.Add(buffer); } } } else { foreach (LogBuffer buffer in _bufferList) { if (buffer.FileInfo == ILogFileInfo) { lastRemovedBuffer = buffer; deleteList.Add(buffer); } } } foreach (LogBuffer buffer in deleteList) { RemoveFromBufferList(buffer); } _lruCacheDictLock.ReleaseWriterLock(); ReleaseBufferListWriterLock(); if (lastRemovedBuffer == null) { Logger.logInfo("lastRemovedBuffer is null"); } else { Logger.logInfo(string.Format("lastRemovedBuffer: startLine={0}", lastRemovedBuffer.StartLine)); } return lastRemovedBuffer; }
public string BuildArgs(ILogLine logLine, int lineNum, ILogFileInfo logFileInfo, Form parent) { StringBuilder builder = new StringBuilder(this.argLine); builder.Replace("%L", "" + lineNum); builder.Replace("%P", logFileInfo.DirectoryName); builder.Replace("%N", logFileInfo.FileName); builder.Replace("%F", logFileInfo.FullName); builder.Replace("%E", Util.GetExtension(logFileInfo.FileName)); string stripped = Util.StripExtension(logFileInfo.FileName); builder.Replace("%M", stripped); builder.Replace("%URI", logFileInfo.Uri.AbsoluteUri); string user = logFileInfo.Uri.UserInfo; if (user.Contains(":")) { user = user.Substring(0, user.IndexOf(':')); } builder.Replace("%S", user); builder.Replace("%R", logFileInfo.Uri.PathAndQuery); builder.Replace("%H", logFileInfo.Uri.Host); builder.Replace("%T", logFileInfo.Uri.Port.ToString()); int sPos = 0; string reg; string replace; do { reg = GetNextGroup(builder, ref sPos); replace = GetNextGroup(builder, ref sPos); if (reg != null && replace != null) { string result = Regex.Replace(logLine.FullLine, reg, replace); builder.Insert(sPos, result); } } while (replace != null); int i = 0; while (i < builder.Length) { // ?"Pinpad-type?"(thales,dione) if (builder[i] == '?') { int end = i; string ask = "Parameter"; if (builder[i + 1] == '"') { end = builder.ToString().IndexOf('"', i + 2); if (end == -1) { end = builder.Length - 1; } ask = builder.ToString().Substring(i + 2, end - i - 2); } string[] values = null; if (builder[end + 1] == '(') { int end2 = builder.ToString().IndexOf(')'); if (end2 == -1) { end2 = builder.Length - 1; } string valueStr = builder.ToString().Substring(end + 2, end2 - end - 2); values = valueStr.Split(new char[] { ',' }, StringSplitOptions.None); end = end2; } ParamRequesterDialog dlg = new ParamRequesterDialog(); dlg.ParamName = ask; dlg.Values = values; DialogResult res = dlg.ShowDialog(parent); if (res == DialogResult.OK) { builder.Remove(i, end - i + 1); builder.Insert(i, dlg.ParamValue); } else if (res == DialogResult.Cancel || res == DialogResult.Abort) { return(null); } } ++i; } return(builder.ToString()); }
//public LogBuffer() { } public LogBuffer(ILogFileInfo fileInfo, int maxLines) { this.FileInfo = fileInfo; this.MAX_LINES = maxLines; }
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(); }
private static bool IsEmptyLog(ILogFileInfo logFileInfo) { return(logFileInfo.Size == 0L); }
public string BuildArgs(string logLine, int lineNum, ILogFileInfo logFileInfo, Form parent) { StringBuilder builder = new StringBuilder(this.argLine); builder.Replace("%L", "" + lineNum); builder.Replace("%P", logFileInfo.DirectoryName); builder.Replace("%N", logFileInfo.FileName); builder.Replace("%F", logFileInfo.FullName); builder.Replace("%E", Util.GetExtension(logFileInfo.FileName)); string stripped = Util.StripExtension(logFileInfo.FileName); builder.Replace("%M", stripped); builder.Replace("%URI", logFileInfo.Uri.AbsoluteUri); string user = logFileInfo.Uri.UserInfo; if (user.Contains(":")) { user = user.Substring(0, user.IndexOf(':')); } builder.Replace("%S", user); builder.Replace("%R", logFileInfo.Uri.PathAndQuery); builder.Replace("%H", logFileInfo.Uri.Host); builder.Replace("%T", logFileInfo.Uri.Port.ToString()); int sPos = 0; string reg; string replace; do { reg = GetNextGroup(builder, ref sPos); replace = GetNextGroup(builder, ref sPos); if (reg != null && replace != null) { string result = Regex.Replace(logLine, reg, replace); builder.Insert(sPos, result); } } while (replace != null); int i = 0; while (i < builder.Length) { // ?"Pinpad-type?"(thales,dione) if (builder[i] == '?') { int end = i; string ask = "Parameter"; if (builder[i + 1] == '"') { end = builder.ToString().IndexOf('"', i + 2); if (end == -1) { end = builder.Length - 1; } ask = builder.ToString().Substring(i + 2, end - i - 2); } string[] values = null; if (builder[end + 1] == '(') { int end2 = builder.ToString().IndexOf(')'); if (end2 == -1) { end2 = builder.Length - 1; } string valueStr = builder.ToString().Substring(end + 2, end2 - end - 2); values = valueStr.Split(new char[] { ',' }, StringSplitOptions.None); end = end2; } ParamRequesterDialog dlg = new ParamRequesterDialog(); dlg.ParamName = ask; dlg.Values = values; DialogResult res = dlg.ShowDialog(parent); if (res == DialogResult.OK) { builder.Remove(i, end - i + 1); builder.Insert(i, dlg.ParamValue); } else if (res == DialogResult.Cancel || res == DialogResult.Abort) { return null; } } ++i; } return builder.ToString(); }
IList<long> _filePositions = new List<long>(); // file position for every line #endif #endregion #region cTor public LogBuffer(ILogFileInfo fileInfo, int maxLines) { FileInfo = fileInfo; MAX_LINES = maxLines; }
//public LogBuffer() { } public LogBuffer(ILogFileInfo fileInfo, int maxLines) { FileInfo = fileInfo; MAX_LINES = maxLines; }