FileRecordSequence.ReadLogRecords Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns an enumerable collection of records in the sequence. This method cannot be inherited.
public:
virtual 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>
override this.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.
Implements
Exceptions
One or more of the arguments are out of range.
The operation cannot be performed because the record sequence was opened with write-only access.
The record sequence is corrupted.
-or-
The record was written with an incompatible version of the record sequence.
The enumeration has ended.
-or-
The enumeration has not been started. A call to MoveNext() must be made.
The method was called after the sequence has been disposed of.
There is not enough memory to continue the execution of the program.
Examples
The following example shows how you can use this method to read the records in a log sequence.
// Read the records added to the log.
public void ReadRecords()
{
Encoding enc = Encoding.Unicode;
Console.WriteLine();
Console.WriteLine("Reading Log Records...");
try
{
foreach (LogRecord record in this.sequence.ReadLogRecords(this.sequence.BaseSequenceNumber, LogRecordEnumeratorType.Next))
{
byte[] data = new byte[record.Data.Length];
record.Data.Read(data, 0, (int)record.Data.Length);
string mystr = enc.GetString(data);
Console.WriteLine(" {0}", mystr);
}
}
catch (Exception e)
{
Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message);
}
Console.WriteLine();
}
' Read the records added to the log.
Public Sub ReadRecords()
Dim enc As Encoding = Encoding.Unicode
Console.WriteLine()
Console.WriteLine("Reading Log Records...")
Try
For Each record In Me.sequence.ReadLogRecords(Me.sequence.BaseSequenceNumber, LogRecordEnumeratorType.Next)
Dim data(record.Data.Length - 1) As Byte
record.Data.Read(data, 0, CInt(Fix(record.Data.Length)))
Dim mystr As String = enc.GetString(data)
Console.WriteLine(" {0}", mystr)
Next record
Catch e As Exception
Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message)
End Try
Console.WriteLine()
End Sub
Remarks
This method returns an enumerable collection of records in the sequence. The order of the enumerated records depends on the value of the logRecordEnum
parameter.