The C# LogReader Class

LogReader provides transaction log replay and iteration for a specific Connection. It can apply a stored log to a database or stream log records to application callbacks in file-based and pipe-based transaction logging scenarios.

For an overview see page C# Classes

Class Definition

    public class LogReader
    {
        // ===== NESTED STRUCT: LogInfo =====
        public struct LogInfo
        {
            public long     StartTransCounter;
            public long     StopTransCounter;
            public long     StoredTransactions;
            public ushort   DiskPageSize;
            public ushort   PageSize;
            public long     LogSize;
            public String[] Labels;
            public bool     CRC;
            public bool     Aligned;
            public bool     DictionaryCompat;
            public bool     TransactionApplyCompat;
            public bool     TransactionAppendCompat;
            public bool     NotCorrupted;
            public bool     Iteratable;
        }

        // ===== INTERFACE: ILogIterator =====
        public interface ILogIterator
        {
            void Create(Object obj);
            void Update(Object obj);
            void Delete(Object obj);
            void DeleteAll(Type type);
            void EndOfTransaction();
        }

        // ===== CONSTRUCTOR =====
        public LogReader(Connection con, string filePath);

        // ===== REPLAY METHODS =====
        public void Apply(int labelId);
        public void Apply();

        // ===== ITERATION METHODS =====
        public void IterateFile(ILogIterator iterator, long memSize, IntPtr hint);
        public void IteratePipe(ILogIterator iterator, long memSize, IntPtr hint);
        public void IteratePipe(ILogIterator iterator, long memSize, IntPtr hint, Database.Device pipe);
        public void StopPipeIteration();

        // ===== INFORMATION METHODS =====
        public LogInfo GetInfo();

        // ===== INTERNAL CALLBACK (do not call) =====
        public int InvokeCallback(ILogIterator iterator, int operation, int classId, IntPtr handle);
    }

Member Descriptions

LogInfo struct (LogReader)
Metadata about a transaction log file: transaction range (Start/StopTransCounter), storage stats (StoredTransactions, LogSize), format details (DiskPageSize, CRC, Aligned), compatibility flags (DictionaryCompat, TransactionApply/AppendCompat), integrity status (NotCorrupted), and replay capability (Iteratable).
ILogIterator interface
Callback interface for processing log entries during iteration. Implement these methods to handle object lifecycle events: Create, Update, Delete, DeleteAll (class-level deletion), and EndOfTransaction (called when RT_OPTION_MARK_LAST_OBJ is set).
LogReader(Connection, string)
Creates a transaction log reader for replaying or inspecting a transaction log. The connection may point to the target database for replay or to a database used for pipe-based iteration. In pipe-based scenarios, filePath can be null.
Apply(int labelId)
Replays transactions from the log into the connected database up to the specified label ID. Use LogWriter.SetLabel() to create recovery points.
Apply()
Overload that replays all transactions in the log file to the end. Equivalent to Apply(-1).
IterateFile(ILogIterator, long, IntPtr)
Iterates through entries from a file-based transaction log, invoking callback methods on the provided ILogIterator. memSize specifies the size of the temporary in-memory database used to reconstruct objects, and hint is an optional native/shared-memory hint used in some runtime configurations.
IteratePipe(ILogIterator, long, IntPtr[, Database.Device])
Iterates through log entries streamed through the transaction log pipe interface. Use the overload with Database.Device when the pipe buffer device is managed explicitly by the application.
StopPipeIteration()
Stops an active pipe-based iteration initiated by IteratePipe(). Use to gracefully terminate real-time log consumption.
GetInfo()
Returns metadata about the log file via the LogInfo structure. Use to verify compatibility, integrity, and available recovery points before replay.
InvokeCallback(...) (internal)
Internal method called by the native layer to dispatch log events to the managed ILogIterator. Applications should never call this method directly.
Replay Safety
Before calling Apply(), verify LogInfo.TransactionApplyCompat and DictionaryCompat are true. Mismatched schema metadata or an incompatible log format can prevent successful replay.
Memory Requirements
The memSize parameter for iteration methods must be large enough to hold the largest object in the log. Insufficient memory causes iteration to fail with out-of-memory errors.
Label-Based Recovery
Use LogWriter.SetLabel() to mark recovery points (e.g., after backups). During recovery, call LogReader.Apply(labelId) to replay only transactions up to the desired checkpoint, minimizing recovery time.
Pipe Synchronization
For real-time log consumption, the writer uses LogFlags.Pipe or LogFlags.DynamicPipe, and the reader consumes records with IteratePipe(). In dynamic-pipe scenarios the application can attach a pipe buffer device and pass it explicitly to IteratePipe(..., Database.Device).
Error Handling
If an ILogIterator callback throws DatabaseError, InvokeCallback returns its error code to the native layer and iteration stops. Application callback code should therefore use predictable error handling.
Schema Dependency
The iteration methods reconstruct managed objects using schema metadata from the current Database and Connection. Use a connection that belongs to a database opened with the matching class dictionary and runtime configuration.
Thread Safety
LogReader instances are not thread-safe. Use separate reader instances per thread. The underlying connection should not be used concurrently for other database operations during log replay.