Editare

Partajați prin


IRecordSequence.ReadLogRecords Method

Definition

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

public:
 System::Collections::Generic::IEnumerable<System::IO::Log::LogRecord ^> ^ ReadLogRecords(System::IO::Log::SequenceNumber start, System::IO::Log::LogRecordEnumeratorType logRecordEnum);
public System.Collections.Generic.IEnumerable<System.IO.Log.LogRecord> ReadLogRecords (System.IO.Log.SequenceNumber start, System.IO.Log.LogRecordEnumeratorType logRecordEnum);
abstract member ReadLogRecords : System.IO.Log.SequenceNumber * System.IO.Log.LogRecordEnumeratorType -> seq<System.IO.Log.LogRecord>
Public Function ReadLogRecords (start As SequenceNumber, logRecordEnum As LogRecordEnumeratorType) As IEnumerable(Of LogRecord)

Parameters

start
SequenceNumber

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

logRecordEnum
LogRecordEnumeratorType

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

Returns

An enumerable collection of records in the sequence.

Exceptions

One or more of the arguments is invalid.

An I/O error occurred while reading the record.

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

Examples

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 {a}");  

         b = AppendRecord(sequence,  
                          "This is record B",  
                          a,  
                          a);  
         Console.WriteLine($"Record B has sequence number {b}");  

         c = AppendRecord(sequence,  
                          "This is record C",  
                          a,  
                          a);  
         Console.WriteLine($"Record C has sequence number {c}");  

         d = AppendRecord(sequence,  
                          "This is record D",  
                          b,  
                          c);  
         Console.WriteLine($"Record D has sequence number {d}");  

         foreach(LogRecord record in  
                 sequence.ReadLogRecords(a, ReadDirection.Forward))  
         {  
             BinaryReader reader = new BinaryReader(record.Data);  
             Console.WriteLine($"{record.SequenceNumber}: {reader.ReadString()}");  
         }  

         foreach(LogRecord record in  
                 sequence.ReadLogRecords(d, ReadDirection.User))  
         {  
             BinaryReader reader = new BinaryReader(record.Data);  
             Console.WriteLine($"{record.SequenceNumber}: {reader.ReadString()}");  
         }  

         foreach(LogRecord record in  
                 sequence.ReadLogRecords(d, ReadDirection.Previous))  
         {  
             BinaryReader reader = new BinaryReader(record.Data);  
             Console.WriteLine($"{record.SequenceNumber}: {reader.ReadString()}");  
         }  
     }  
       }  

Remarks

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.

Applies to