IRecordSequence.ReadLogRecords 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在派生类中重写时,返回序列中记录的可枚举集合。
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
参数的值。