Exemplo n.º 1
0
            public List <ApplicationLogEntry> ReadNextBatch(int batchSize)
            {
                if (_disposed)
                {
                    throw new ObjectDisposedException("_enumerator");
                }

                ApplicationLogEntry        currentEntry = new ApplicationLogEntry();
                List <ApplicationLogEntry> entries      = new List <ApplicationLogEntry>();

                if (_enumerator == null)
                {
                    _enumerator = _lines.GetEnumerator();
                }

                while (entries.Count < batchSize && _enumerator.MoveNext())
                {
                    string line  = _enumerator.Current;
                    var    match = Regex.Match(line, ApplicationLogsReader.LogEntryRegexPattern, RegexOptions.IgnoreCase);
                    if (match.Success)
                    {
                        currentEntry.TimeStamp = DateTimeOffset.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                        currentEntry.PID       = int.Parse(match.Groups[2].Value);
                        currentEntry.Level     = match.Groups[3].Value;
                        currentEntry.AddMessageLine(match.Groups[4].Value);
                        entries.Add(currentEntry);
                        currentEntry = new ApplicationLogEntry();
                    }
                    else
                    {
                        currentEntry.AddMessageLine(line);
                    }
                }

                if (entries.Count > 0)
                {
                    this.LastTime = entries.Last().TimeStamp;
                }

                return(entries);
            }