override public string ToString() { try { var line = LineRegex.Replace(Lines[0].ToString(), "\r\n|\t"); var match = DateTimeRegex.Match(line); if (match.Success) line = match.Groups[3].Value; sb.AppendFormat("{0}\r\n", line); //首行 for (var i = 1; i < Lines.Length; ++i) //从第二行开始 { var other = Lines[i].ToString(); sb.AppendFormat("|\t{0}\r\n", LineRegex.Replace(other, "\r\n|\t")); } string ret = sb.ToString(); sb.Remove(0, sb.Length); return ret; } catch (System.Exception e) { return "Log ToString Error" + e; } }
protected DateTime ParseDateTime(string value) { try { // regex - parse exact doesn't work. if (DateTimeRegex == null) { throw new InvalidOperationException("DateTimeRegex is null."); } Match match = DateTimeRegex.Match(value); if (match.Success) { // create... int day = ConversionHelper.ToInt32(match.Groups["day"].Value, Cultures.System); string monthAsString = match.Groups["month"].Value; int year = ConversionHelper.ToInt32(match.Groups["year"].Value, Cultures.System); int hour = ConversionHelper.ToInt32(match.Groups["hour"].Value, Cultures.System); int minute = ConversionHelper.ToInt32(match.Groups["minute"].Value, Cultures.System); int second = ConversionHelper.ToInt32(match.Groups["second"].Value, Cultures.System); // get... int month = 0; for (int index = 1; index <= 12; index++) { string name = DateTimeFormatInfo.InvariantInfo.GetAbbreviatedMonthName(index); if (string.Compare(name, monthAsString, true, System.Globalization.CultureInfo.InvariantCulture) == 0) { month = index; break; } } // check... if (month == 0) { throw new InvalidOperationException(string.Format("'{0}' is not a valid month name.", monthAsString)); } // create... return(new DateTime(year, month, day, hour, minute, second)); } else { throw new InvalidOperationException("Regular expression matching failed when checking the date."); } } catch (Exception ex) { throw new InvalidOperationException(string.Format("Failed to convert '{0}' to a date/time.", value), ex); } }