本文整理汇总了VB.NET中System.IO.Log.FileRecordSequence类的典型用法代码示例。如果您正苦于以下问题:VB.NET FileRecordSequence类的具体用法?VB.NET FileRecordSequence怎么用?VB.NET FileRecordSequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileRecordSequence类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: MyLog
Public Class MyLog
Private logName As String = "test.log"
Private sequence As FileRecordSequence = Nothing
Private delete As Boolean = True
Public Sub New()
' Create a FileRecordSequence.
sequence = New FileRecordSequence(logName, FileAccess.ReadWrite)
End Sub
' Append records to the record sequence.
Public Sub AppendRecords()
Console.WriteLine("Appending Log Records...")
Dim previous As SequenceNumber = SequenceNumber.Invalid
previous = sequence.Append(CreateData("Hello World!"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)
previous = sequence.Append(CreateData("This is my first Logging App"), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)
previous = sequence.Append(CreateData("Using FileRecordSequence..."), SequenceNumber.Invalid, SequenceNumber.Invalid, RecordAppendOptions.ForceFlush)
Console.WriteLine("Done...")
End Sub
' 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
' Dispose the record sequence and delete the log file.
Public Sub Cleanup()
' Dispose the sequence.
sequence.Dispose()
' Delete the log file.
If delete Then
Try
File.Delete(Me.logName)
Catch e As Exception
Console.WriteLine("Exception {0} {1}", e.GetType(), e.Message)
End Try
End If
End Sub
' Converts the given data to an Array of ArraySegment<byte>
Public Shared Function CreateData(ByVal str As String) As IList(Of ArraySegment(Of Byte))
Dim enc As Encoding = Encoding.Unicode
Dim array() As Byte = enc.GetBytes(str)
Dim segments(0) As ArraySegment(Of Byte)
segments(0) = New ArraySegment(Of Byte)(array)
Return System.Array.AsReadOnly(Of ArraySegment(Of Byte))(segments)
End Function
End Class
Friend Class LogSample
Private Shared Sub Main2(ByVal args() As String)
Dim log As New MyLog()
log.AppendRecords()
log.ReadRecords()
log.Cleanup()
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.IO.Log,代码行数:80,代码来源:FileRecordSequence
注:本文中的System.IO.Log.FileRecordSequence类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论