コード例 #1
0
        /// <summary>
        /// Advances the enumerator to the next log item of the currently read log file. If there
        /// are no more items in this file and there is a NextReader set, the first log item of the
        /// next file reader is selected. If there are no more items in this file and WaitMode is
        /// set, the method will block until another log item is appended to the current file or
        /// the wait operation is cancelled by a close event.
        /// </summary>
        /// <returns>true if the enumerator was successfully advanced to the next log item;
        /// false if the enumerator has passed the end of the collection.</returns>
        public bool MoveNext()
        {
            FieldLogFileReader nextReader = null;

            do
            {
                if (nextReader != null)
                {
                    FL.Trace(reader.ItemCount + " items read from " + Path.GetFileName(reader.FileName));
                    reader = nextReader;
                    FL.Trace("Switching to next reader " + Path.GetFileName(reader.FileName));
                }

                try
                {
                    item = reader.ReadLogItem();
                }
                catch (Exception ex)
                {
                    FL.Error(ex, "Reading item from log file");
                    OnError(ex);
                    // Skip the rest of the current file and continue with the next one if
                    // available. If this is the last file and WaitMode is set, this priority will
                    // not be monitored anymore.
                    item = null;
                }

                if (item == null && reader.IsClosing)
                {
                    // Close event must have been set
                    Dispose();
                    return(false);
                }
                nextReader = reader.NextReader;
            }while (item == null && nextReader != null);
            return(item != null);
        }