This documentation is archived and is not being maintained.

IRecordSequence.ReadLogRecords Method

When overridden in a derived class, returns an enumerable collection of records in the sequence.

Namespace:  System.IO.Log
Assembly:  System.IO.Log (in System.IO.Log.dll)

IEnumerable<LogRecord> ReadLogRecords(
	SequenceNumber start,
	LogRecordEnumeratorType logRecordEnum
)

Parameters

start
Type: System.IO.Log.SequenceNumber

The sequence number of the first record where the reading starts.

logRecordEnum
Type: System.IO.Log.LogRecordEnumeratorType

A valid LogRecordEnumeratorType value that specifies the manner (that is, forward or backward) in which records should be read from a LogRecordSequence.

Return Value

Type: System.Collections.Generic.IEnumerable<LogRecord>
An enumerable collection of records in the sequence.

ExceptionCondition
ArgumentException

One or more of the arguments is invalid.

IOException

An I/O error occurred while reading the record.

ObjectDisposedException

The method was called after the sequence has been disposed of.

When overridden in a derived class, returns an enumerable collection of records in the sequence. The order of the enumerated records depends on the value of the logRecordEnum parameter.

This sample demonstrates the use of the ReadLogRecords method.

using System;
 using System.IO;
 using System.IO.Log;
 
 class ReadRecordsSample
 {
     static SequenceNumber AppendRecord(IRecordSequence sequence,
                                        string message,
                                        SequenceNumber user,
                                        SequenceNumber previous)
     {
         MemoryStream data = new MemoryStream();
         BinaryWriter writer = new BinaryWriter(data);
         writer.Write(message);
 
         ArraySegment<byte>[] segments;
         segments = new ArraySegment<byte>[1];
         segments[0] = new ArraySegment(data.GetBuffer(),
                                        0,
                                        Data.Length);
 
         return sequence.Append(segments,
                                user,
                                previous,
                                WriteFlags.None);
     }
 
     public static void Main(string[] args)
     {
         IRecordSequence sequence;
         sequence = new FileIRecordSequence(args[0]);
 
         SequenceNumber a, b, c, d;
 
         a = AppendRecord(sequence,
                          "This is record A",
                          SequenceNumber.Invalid,
                          SequenceNumber.Invalid);
         Console.WriteLine("Record A has sequence number System.IO.Log", a);
         
         b = AppendRecord(sequence,
                          "This is record B",
                          a,
                          a);
         Console.WriteLine("Record B has sequence number System.IO.Log", b);
 
         c = AppendRecord(sequence,
                          "This is record C",
                          a,
                          a);
         Console.WriteLine("Record C has sequence number System.IO.Log", c);
 
         d = AppendRecord(sequence,
                          "This is record D",
                          b,
                          c);
         Console.WriteLine("Record D has sequence number System.IO.Log", d);
 
         foreach(LogRecord record in
                 sequence.ReadLogRecords(a, ReadDirection.Forward))
         {
             BinaryReader reader = new BinaryReader(record.Data);
             Console.WriteLine("System.IO.Log: T:System.IO.Log.IRecordSequence",
                               record.SequenceNumber,
                               reader.ReadString());
         }
 
         foreach(LogRecord record in
                 sequence.ReadLogRecords(d, ReadDirection.User))
         {
             BinaryReader reader = new BinaryReader(record.Data);
             Console.WriteLine("System.IO.Log: T:System.IO.Log.IRecordSequence",
                               record.SequenceNumber,
                               reader.ReadString());
         }
 
         foreach(LogRecord record in
                 sequence.ReadLogRecords(d, ReadDirection.Previous))
         {
             BinaryReader reader = new BinaryReader(record.Data);
             Console.WriteLine("System.IO.Log: T:System.IO.Log.IRecordSequence",
                               record.SequenceNumber,
                               reader.ReadString());
         }
     }
       }

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Show: