static readonly Regex ParseLineRegex = new Regex(@"^(?<ip>\S*) - - \[(?<date>.*)\] (?<method>\S+) (?<url>.+) (?<code>\d+) (?<tail>.+)", RegexOptions.Compiled); DataColumn ip1 = new DataColumn("IP Address"); DataColumn date1 = new DataColumn("Date"); DataColumn method1 = new DataColumn("Method"); DataColumn url1 = new DataColumn("URL"); DataColumn code1 = new DataColumn("Code"); DataColumn tail1 = new DataColumn("Tail"); ip1.DataType = System.Type.GetType("System.String"); date1.DataType = System.Type.GetType("System.String"); method1.DataType = System.Type.GetType("System.String"); url1.DataType = System.Type.GetType("System.String"); code1.DataType = System.Type.GetType("System.String"); tail1.DataType = System.Type.GetType("System.String"); dt.Columns.Add(ip1); dt.Columns.Add(date1); dt.Columns.Add(method1); dt.Columns.Add(url1); dt.Columns.Add(code1); dt.Columns.Add(tail1); using (StreamReader reader = new StreamReader(txtSource)) { while ((line = reader.ReadLine()) != null) { var match = ParseLineRegex.Match(line); if (match.Success) { //ip, date, method, url, code and tail - Parsing var ip = match.Groups["ip"].Value; var date = match.Groups["date"].Value; var method = match.Groups["method"].Value; var url = match.Groups["url"].Value; var code = match.Groups["code"].Value; var tail = match.Groups["tail"].Value; #region Viewing Purposes dr[ip1] = ip; dr[date1] = date; dr[method1] = method; dr[url1] = url; dr[code1] = code; dr[tail1] = tail; dt.Rows.Add(dr.ItemArray); #endregion } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)