LogRecordSequence.Append Method (ArraySegment<Byte>, SequenceNumber, SequenceNumber, RecordAppendOptions)

 

Writes a log record to the LogRecordSequence. This method cannot be inherited.

Namespace:   System.IO.Log
Assembly:  System.IO.Log (in System.IO.Log.dll)

public SequenceNumber Append(
	ArraySegment<byte> data,
	SequenceNumber nextUndoRecord,
	SequenceNumber previousRecord,
	RecordAppendOptions recordAppendOptions
)

Parameters

data
Type: System.ArraySegment<Byte>

A list of byte array segments that will be concatenated and appended as the record.

nextUndoRecord
Type: System.IO.Log.SequenceNumber

The sequence number of the next record in the user-specified order.

previousRecord
Type: System.IO.Log.SequenceNumber

The sequence number of the next record in Previous order.

recordAppendOptions
Type: System.IO.Log.RecordAppendOptions

A valid value of RecordAppendOptions that specifies how the data should be written.

Return Value

Type: System.IO.Log.SequenceNumber

The sequence number of the appended log record.

Exception Condition
ArgumentException

userRecord or previousRecord is not valid for this sequence.

-or-

data cannot be appended because it is larger than the maximum record size.

-or-

reservations was not created by this record sequence.

ArgumentNullException

One or more of the arguments are null.

ArgumentOutOfRangeException

userRecord or previousRecord is not between the base and last sequence numbers of this sequence.

IOException

The request could not be performed because of an unexpected I/O exception.

-or-

The request could not be performed because of an I/O device error.

NotSupportedException

The operation cannot be performed because the record sequence was opened with read-only access.

ObjectDisposedException

The method was called after the sequence has been disposed of.

OutOfMemoryException

There is not enough memory to continue the execution of the program.

SequenceFullException

The record sequence is full.

UnauthorizedAccessException

Access for the specified log sequence is denied by the operating system.

Data contained in the data parameter will be concatenated into a single byte array for appending as the record. However, no provision is made for splitting data back into array segments when the record is read.

Normally, this method completes before the record has been written. To ensure that a record has been written, either specify the ForceFlush flag using the recordAppendOptions parameter, or call the Flush method.

The following example demonstrates how to use this method to append a log record to the sequence.

// Start Appending in two streams with interleaving appends.

		SequenceNumber previous1 = SequenceNumber.Invalid;
		SequenceNumber previous2 = SequenceNumber.Invalid;

		Console.WriteLine("Appending interleaving records in stream1 and stream2...");
		Console.WriteLine();
// Append two records in stream1.
		previous1 = sequence1.Append(
			CreateData("MyLogStream1: Hello World!"),
			SequenceNumber.Invalid,
			SequenceNumber.Invalid,
			RecordAppendOptions.ForceFlush);
		previous1 = sequence1.Append(
			CreateData("MyLogStream1: This is my first Logging App"),
			previous1,
			previous1,
			RecordAppendOptions.ForceFlush);

// Append two records in stream2.
		previous2 = sequence2.Append(
			CreateData("MyLogStream2: Hello World!"),
			SequenceNumber.Invalid,
			SequenceNumber.Invalid,
			RecordAppendOptions.ForceFlush);
		previous2 = sequence2.Append(
			CreateData("MyLogStream2: This is my first Logging App"),
			previous2,
			previous2,
			RecordAppendOptions.ForceFlush);

// Append the third record in stream1.
		previous1 = sequence1.Append(CreateData(
			"MyLogStream1: Using LogRecordSequence..."),
			previous1,
			previous1,
			RecordAppendOptions.ForceFlush);

// Append the third record in stream2.
		previous2 = sequence2.Append(
			CreateData("MyLogStream2: Using LogRecordSequence..."),
			previous2,
			previous2,
			RecordAppendOptions.ForceFlush);

.NET Framework
Available since 3.0
Return to top
Show: