共用方式為


IRecordSequence.ReadLogRecords 方法

定義

在衍生類別中覆寫時,將順序中的記錄的可列舉集合傳回。

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)

參數

start
SequenceNumber

開始讀取之第一筆記錄的序號。

logRecordEnum
LogRecordEnumeratorType

LogRecordEnumeratorType 的有效值,其中指定從 LogRecordSequence 讀取記錄的方式 (即往前或往後讀取)。

傳回

順序中的記錄的可列舉集合。

例外狀況

一或多個引數無效。

讀取記錄時發生 I/O 錯誤。

已在處置序列之後呼叫此方法。

範例

這個範例將示範如何使用 ReadLogRecords 方法。

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

備註

在衍生類別中覆寫時,將順序中的記錄的可列舉集合傳回。 列舉的記錄順序取決於 logRecordEnum 參數的值。

適用於