private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { _dtlogEntries.Clear(); _colWatchedFiles.Clear(); lstFiles.Items.Clear(); _objChosenBehavior = null; RefreshFilter(); }
private void loadServerListToolStripMenuItem_Click(object sender, EventArgs e) { if (_frmBatchCollector.ShowDialog() == DialogResult.OK) { if (!string.IsNullOrEmpty(_frmBatchCollector.BehaviorName)) { var beh = _colBehaviors.Where(b => b.BehaviorName.Equals(_frmBatchCollector.BehaviorName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (beh != null) _objChosenBehavior = beh; } if (_frmBatchCollector.LogDirectories.Count == 0) { _objGlobalLineFilter = _frmBatchCollector.CardsLineFilter; } ProgressBarManager.ShowProgressBar(100); foreach (string directory in _frmBatchCollector.LogDirectories) ProcessLogDirectory(_frmBatchCollector.ExcludeList, _frmBatchCollector.IncludeList, _frmBatchCollector.CardsLineFilter, _frmBatchCollector.History, directory); ProgressBarManager.CloseProgress(); //perform a memory collection GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } }
//move to engine /// <summary> /// parses log file from the given position and on /// </summary> /// <param name="p_strLogFileName"></param> /// <param name="p_intStartPos"></param> /// <returns></returns> public long ParseLogFileRegExp(string p_strLogFileName, long p_intStartPos, LogBehavior behaviorForCurrentFile) { //m_dtlogEntries.BeginLoadData(); long lngFileTotalBytes = 0; long progressbytes = 0; try { using (FileStream objFStream = new FileStream(p_strLogFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { objFStream.Position = p_intStartPos; using (StreamReader objReader = new StreamReader(objFStream, CurrentEncoding)) { string strAllText = objReader.ReadToEnd(); lngFileTotalBytes = strAllText.Length; //m_drPrevRow = drRow; MatchCollection colMatches = behaviorForCurrentFile.ParserRegex.Matches(strAllText); foreach (Match match in colMatches) { int increment = (int)((double)lngFileTotalBytes / (double)colMatches.Count); progressbytes += increment; ProgressBarManager.IncrementProgress(increment); if (!IsLineInFilter(p_strLogFileName, match.Value)) { continue; } LogEntry drRow = new LogEntry(); string strDate = match.Groups["date"].Value; string strThread = match.Groups["thread"].Value; string strLevel = match.Groups["level"].Value; string strComputer = match.Groups["computer"].Value; string strUser = match.Groups["user"].Value; string strInfo = match.Groups["info"].Value; string strInfoEx = match.Groups["exinfo"].Value.TrimEnd(); string strMachine = match.Groups["machine"].Value; LogEntry row = new LogEntry(); drRow.ErrorInfo = strInfoEx; //"14/11 16:39:03,236" DateTime dtmTemp = DateTime.Now; bool ok = System.DateTime.TryParseExact(strDate, behaviorForCurrentFile.DateFormat, Application.CurrentCulture, System.Globalization.DateTimeStyles.None, out dtmTemp); if (!ok) ok = System.DateTime.TryParseExact(strDate + "0", behaviorForCurrentFile.DateFormat, Application.CurrentCulture, System.Globalization.DateTimeStyles.None, out dtmTemp); if (!ok) ok = System.DateTime.TryParseExact(strDate + "00", behaviorForCurrentFile.DateFormat, Application.CurrentCulture, System.Globalization.DateTimeStyles.None, out dtmTemp); if (!ok) drRow.EntryTime = DateTime.MinValue; else drRow.EntryTime = dtmTemp; if (strLevel.ToLower().StartsWith("trac")) strLevel = "TRACE"; else if (strLevel.ToLower().StartsWith("inf")) strLevel = "INFO"; else if (strLevel.ToLower().StartsWith("deb")) strLevel = "DEBUG"; else if (strLevel.ToLower().StartsWith("err")) strLevel = "ERROR"; else if (strLevel.ToLower().StartsWith("fat")) strLevel = "FATAL"; else if (strLevel.ToLower().StartsWith("warn")) strLevel = "WARN"; //drRow.EntryTime = DateTime.Parse(strDate); drRow.ComputerName = strComputer; drRow.UserName = strUser; drRow.ThreadName = strThread; drRow.Info = strInfo; drRow.LogLevel = strLevel; drRow.SourceLogFile = Path.GetFileName(p_strLogFileName); drRow.UserName = strUser; drRow.ComputerName = strMachine; if (p_strLogFileName.StartsWith("\\\\")) { drRow.ServerName = p_strLogFileName.Substring(2, p_strLogFileName.IndexOf('\\', 3) - 2); } else drRow.ServerName = "localhost"; //if (IsLineInFilter(p_strLogFileName, drRow.Info + " " + drRow.RowError)) //m_dtlogEntries.AddLogEntriesRow(drRow); //if (IsLineInFilter(p_strLogFileName, match.Value)) //{ _dtlogEntries.Add(drRow); drRow.Key = _dtlogEntries.Count; //} } ProgressBarManager.IncrementProgress(lngFileTotalBytes - progressbytes); } } } catch { //only open a file in notepad if it's a new file causing the problem... if (p_intStartPos == 0) { FRMVanishingAlert.ShowForm(2, "Wrong Log Format", "Not a known log,\r\n\rOpening Notepad", "", "", 0, 0, true, FormStartPosition.Manual, false); string strWinDir = Environment.GetEnvironmentVariable("SystemRoot"); Process.Start(strWinDir + "\\notepad.exe", p_strLogFileName); //this.Visible = false; } return long.MinValue; } return lngFileTotalBytes; }
//move to engine public bool AddFile(string file) { if (file.Trim() == "") return true; LogBehavior behaviorForCurrentFile = _objChosenBehavior; bool blnLiveListen = false; string strLiveListen = ConfigurationManager.AppSettings["LiveListeningOnByDefault"]; if (strLiveListen != null && strLiveListen.Equals("true", StringComparison.InvariantCultureIgnoreCase)) blnLiveListen = true; if (timer1.Enabled == false && blnLiveListen) { timer1.Enabled = true; timer1.Start(); } //dataGridView1.DataSource = new BindingList<DSLogData.LogEntriesRow>(m_dvMainView.ToList()); //if (dataGridView1.Columns.Contains("EntryTime")) //{ // dataGridView1.Columns["EntryTime"].DefaultCellStyle.Format = DATE_TIME_FORMAT; // dataGridView1.Columns["EntryTime"].Width = 134; //} //string dir = Path.GetDirectoryName(file); //FileAttributes att = File.GetAttributes(file); if (!_colWatchedFiles.ContainsKey(file)) { behaviorForCurrentFile = FindCorrectBehaviorForFile(file); if (_objChosenBehavior != null && !IsAutoDetectMode) { _objChosenBehavior = behaviorForCurrentFile; cmbBehaviors.SelectedItem = _objChosenBehavior; if (_objChosenBehavior != null) { //set the grid columns dataGridView1.Columns.Clear(); _objChosenBehavior.CreateGridCols(dataGridView1); //set the default error level filter to initialize display. string strDefaultLevel = ConfigurationManager.AppSettings["DefaultLogLevel"]; if (!string.IsNullOrEmpty(strDefaultLevel)) { for (int i = 0; i < cmbLevel.Items.Count; ++i) { string item = (string)cmbLevel.Items[i]; if (item.Equals(strDefaultLevel, StringComparison.InvariantCultureIgnoreCase)) cmbLevel.SelectedIndex = i; } cmbBehaviors_SelectedIndexChanged(null, null); } } } //if there was no chosen behavior, return false if (behaviorForCurrentFile == null) { OpenNotepad(file); return false; } int intCountBefore = dataGridView1.Rows.Count; //parse the log file (using the chosen behaviour's regexp) long readBytes = ParseLogFileRegExp(file, 0, behaviorForCurrentFile); ////if no bytes were read, or an error occured, return false //if (readBytes == long.MinValue || readBytes == 0) //{ // OpenNotepad(file); // return false; //} ////if there were no lines read from this file //if (intCountBefore == dataGridView1.Rows.Count) //{ // OpenNotepad(file); // return false; //} _colWatchedFiles.Add(file, new FileInfo(file).Length); lstFiles.Items.Add(file); } lblCount.Text = "Total Count: " + _dvMainView.Count(); lblMemory.Text = "Used Ram: " + ((double)Process.GetCurrentProcess().WorkingSet64 / 1000000d).ToString(".00") + " MB"; RefreshFilter(); //success return true; }
//move to engine private void RepaseAllLogs(LogBehavior b) { _dtlogEntries.Clear(); _objChosenBehavior = b; //set the grid columns dataGridView1.Columns.Clear(); _objChosenBehavior.CreateGridCols(dataGridView1); LogBehavior behavior = _objChosenBehavior; foreach (string file in _colWatchedFiles.Keys.ToList()) { if (IsAutoDetectMode) { behavior = FindCorrectBehaviorForFile(file); } ParseLogFileRegExp(file, 0, behavior); } }
/// <summary> /// parse all logs according to the given behavior /// </summary> /// <param name="b"></param> internal void ReparseAllLogs(LogBehavior b) { _dtlogEntries.Clear(); _objChosenBehavior = b; LogBehavior behavior = _objChosenBehavior; foreach (string file in WatchedFiles) { if (IsAutoDetectMode) { behavior = FindCorrectBehaviorForFile(file); } ParseLogFileRegExp(file, 0, behavior); } }
private static LogBehavior CreateAutoBehaviour() { LogBehavior b = new LogBehavior(); //b.GridCols.Add("key"); b.GridCols.Add("date"); b.GridCols.Add("level"); b.GridCols.Add("info"); b.GridCols.Add("exinfo"); b.GridCols.Add("thread"); // b.GridCols.Add("sourcefile"); b.BehaviorName = "AutoDetect"; return b; }