コード例 #1
0
        /// <summary>
        ///     Gets the specified log entries from the active log file.
        /// </summary>
        /// <param name="id">
        ///     An id identifying the log entry where the query operation starts.
        /// </param>
        /// <param name="direction">
        ///     An enumeration indicating the direction of the query task.
        /// </param>
        /// <param name="count">
        ///     The number of event log entries to retrieve.
        /// </param>
        /// <returns>
        ///     A collection of the entries contained within the active log file.
        /// </returns>
        public static EventLogEntryCollection GetEntries(Guid id, EventLogDirection direction, int count)
        {
            var entries = new EventLogEntryCollection( );

            // Check for valid query options
            if (id != Guid.Empty)
            {
                // Load the active log entries
                EventLogEntryCollection activeEntries = LoadActiveLog( );

                // Check if the specified entry exists (using LINQ)
                int index = activeEntries.FindIndex(entry => entry.Id == id);
                if (index >= 0)
                {
                    if (direction == EventLogDirection.FirstToLast)
                    {
                        // Move the index forward by one position (i.e. next position)
                        index = index + 1;

                        // Determine the number of log entries to retreive
                        count = (activeEntries.Count - index < count) ? activeEntries.Count - index : count;

                        // Copy the specified log entries (oldest to newest)
                        for (int x = 0; x < count; ++x)
                        {
                            var i = index + x;
                            if (i >= 0 && i < activeEntries.Count)  //assert true .. but something is failing intermittently
                            {
                                entries.Add(activeEntries[i]);
                            }
                        }
                    }
                    else if (direction == EventLogDirection.LastToFirst)
                    {
                        // ToDo: Implement
                    }
                }
            }

            return(entries);
        }
コード例 #2
0
        /// <summary>
        ///     Gets the specified log entries from the active log file.
        /// </summary>
        /// <param name="origin">
        ///     An enumeration indicating where the query operation starts.
        /// </param>
        /// <param name="direction">
        ///     An enumeration indicating the direction of the query task.
        /// </param>
        /// <param name="count">
        ///     The number of event log entries to retrieve.
        /// </param>
        /// <returns>
        ///     A collection of the entries contained within the active log file.
        /// </returns>
        public static EventLogEntryCollection GetEntries(EventLogOrigin origin, EventLogDirection direction, int count)
        {
            var entries = new EventLogEntryCollection( );

            // Load the active log entries
            EventLogEntryCollection activeEntries = LoadActiveLog( );

            // Check for valid query options
            if ((origin == EventLogOrigin.First) && (direction == EventLogDirection.FirstToLast))
            {
                count = (activeEntries.Count < count) ? activeEntries.Count : count;

                // Copy the specified log entries (oldest to newest)
                for (int x = 0; x < count; ++x)
                {
                    if (x >= 0 && x < activeEntries.Count)                 //assert true .. but something is failing intermittently
                    {
                        entries.Add(activeEntries[x]);
                    }
                }
            }
            else if ((origin == EventLogOrigin.Last) && (direction == EventLogDirection.LastToFirst))
            {
                count = (activeEntries.Count < count) ? activeEntries.Count : count;

                // Copy the specified log entries (newest to oldest)
                for (int x = count - 1; x >= 0; --x)
                {
                    if (x >= 0 && x < activeEntries.Count) //assert true .. but something is failing intermittently
                    {
                        entries.Add(activeEntries[x]);
                    }
                }
            }

            return(entries);
        }