Bagikan melalui


IRecordSequence.ReadLogRecords Metode

Definisi

Saat ditimpa di kelas turunan, mengembalikan kumpulan rekaman yang dapat dijumlahkan dalam urutan.

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)

Parameter

start
SequenceNumber

Nomor urut rekaman pertama tempat pembacaan dimulai.

logRecordEnum
LogRecordEnumeratorType

Nilai valid LogRecordEnumeratorType yang menentukan cara (yaitu, maju atau mundur) di mana rekaman harus dibaca dari LogRecordSequence.

Mengembalikan

Kumpulan rekaman yang dapat dijumlahkan secara berurutan.

Pengecualian

Satu atau beberapa argumen tidak valid.

Terjadi kesalahan I/O saat membaca rekaman.

Metode ini dipanggil setelah urutan dibuang.

Contoh

Sampel ini menunjukkan penggunaan ReadLogRecords metode .

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

Keterangan

Saat ditimpa di kelas turunan, mengembalikan kumpulan rekaman yang dapat dijumlahkan dalam urutan. Urutan rekaman yang dijumlahkan tergantung pada nilai logRecordEnum parameter.

Berlaku untuk