private static object ReadLogFiles() { string archiveFolder = null; string folder = null; string server = null; WebRequest FileRequest; WebResponse FileResponse; //StreamReader reader; try { if (!string.IsNullOrEmpty(machineNames.ToString()) && !string.IsNullOrEmpty(machineNames.ToString())) { for (int k = 0; k < machineNames.Length; k++) { server = machineNames[k]; archiveFolder = System.Configuration.ConfigurationManager.AppSettings["ArchiveFolder"]; folder = System.Configuration.ConfigurationManager.AppSettings["LogFolder"]; folder = Path.Combine(@"\\" + machineNames[k] + folder); archiveFolder = Path.Combine(@"\\" + machineNames[k] + archiveFolder, "Archive\\\\"); DateTime Lastmodifieddate = System.IO.File.GetLastWriteTime(folder); directoryInfo = new DirectoryInfo(folder); files = directoryInfo.GetFiles(); for (int i = 0; i < files.Length; i++) { string fileCreationtime = files[i].CreationTime.ToShortDateString(); string currentDateTime = DateTime.Now.ToShortDateString(); FileRequest = System.Net.WebRequest.Create(files[i].FullName); if (IsFileBlocked(files[i].FullName)) { continue; } FileResponse = FileRequest.GetResponse(); Stream dataStream = FileResponse.GetResponseStream(); using (StreamReader reader = new StreamReader(dataStream)) { GetFiles getFiles = new GetFiles(); getFiles.ParseLogData(reader, server); reader.Dispose(); MoveFile(archiveFolder, files[i].FullName.ToString()); } } } } } catch (Exception ex) { //throw; } return(null); }
public void ParseLogData(StreamReader reader, string machineName) { try { GetFiles getDates = new GetFiles(); while ((!string.IsNullOrEmpty(Line = reader.ReadLine())) && !string.IsNullOrEmpty(reader.ToString()) && Line != "\u0003##### END OF LOG #####") { bool succeeded = false; bool failed = false; splitLines = null; splitLines = Regex.Split(Line, @"\s{2,}"); if (splitLines[1].ToLower().Contains("authenticate request")) { subscriber = Regex.Split(splitLines[1].ToLower(), "authenticate request"); subscriber1 = subscriber[1]; } //if (splitLines.Length >= 2 && splitLines[1].ToLower().Contains("url") && splitLines[1].ToLower().Contains("method") && splitLines[1].ToLower().Contains("request started") && !string.IsNullOrEmpty(splitLines.ToString())) //{ // str = Regex.Split(splitLines[1], @", "); // result = getDates.GetDates(splitLines); // if (result.Count != 0 && !string.IsNullOrEmpty(result.ToString())) // { // requestStartTime = result[3].ToString(); // requestStartDateTime = DateTime.Parse(result[5].ToString()); // //requestStartDateTime = requestStartDateTime.Value.AddMilliseconds(milliseconds); // pId = result[0].ToString(); // tId = result[1].ToString(); // if (result[4] != null) // method = result[4].ToString(); // if (result[2] != null) // URL = str[2].Substring(4, str[2].Length - 4); // } //} //else if (splitLines.Length >= 2 && requestStartDateTime != null && (splitLines[1].ToLower().Contains("error") || splitLines[1].ToLower().Contains("failed") || splitLines[1].ToLower().Contains("exception"))) //{ // result = getDates.GetDates(splitLines); // if (result.Count != 0 && !string.IsNullOrEmpty(result.ToString())) // { // failedRequestTime = result[3].ToString(); // failedRequestDateTime = Convert.ToDateTime(result[4]); // timetaken = (DateTime.Parse(failedRequestTime.ToString())).Subtract(DateTime.Parse(requestStartTime.ToString())); // timetaken1 = timetaken.ToString(@"hh\:mm\:ss\:fff"); // //int timetaken = DateTime.Compare(DateTime.Parse(failedRequestDateTime.ToString()), DateTime.Parse(failedRequestDateTime.ToString())); // failedRequest = "Failed"; // failed = true; // } //} //else if (splitLines.Length >= 2 && requestStartDateTime != null && (splitLines[1].ToLower().Contains("response recived") || splitLines[1].ToLower().Contains("successfully"))) //{ // result = getDates.GetDates(splitLines); // if (result.Count != 0 && !string.IsNullOrEmpty(result.ToString())) // { // successTime = result[3].ToString(); // successDateTime = Convert.ToDateTime(result[4]); // timetaken = (DateTime.Parse(successTime.ToString())).Subtract(DateTime.Parse(requestStartTime.ToString())); // timetaken1 = timetaken.ToString(@"hh\:mm\:ss\:fff"); // success = "Success"; // succeeded = true; // } //} //if (!string.IsNullOrEmpty(URL) && (succeeded || failed)) //{ // // datalayer.Insert(ref machineName, ref tId, ref pId, ref requestStartDateTime, ref requestStartTime, ref URL, ref method, ref failedRequestDateTime, ref failedRequestTime, ref failedRequest, ref successDateTime, ref successTime, ref success, ref timetaken1); //} if (!string.IsNullOrWhiteSpace(subscriber1)) { DataLayer datalayer = new DataLayer(); datalayer.Insert(ref machineName, ref subscriber1); } } reader.Close(); reader.Dispose(); } catch (Exception ex) { //throw; } }