The C# LogWriter Class

LogWriter provides transaction log writing for a specific Connection. It is used to start, control, and inspect eXtremeDB transaction logging for file-based or pipe-based replication workflows.

For an overview see page C# Classes

Class Definition

    [Flags]
    public enum LogFlags : ushort
    {
        Aligned          = 0x01,   // Start each record with new disk page
        Append           = 0x02,   // Append to an existing log file
        Crc              = 0x04,   // Cover transaction data with CRC32
        SizeCallback     = 0x08,   // User callback to limit size (not supported in .NET)
        SyncInstantly    = 0x10,   // Do disk flush on each record
        SyncTimer        = 0x20,   // Do disk flush by timer
        SyncCount        = 0x40,   // Do disk flush by record count
        Iterable         = 0x80,   // Make log applicable for LogReader iteration
        Restart          = 0x100,  // Stop previous log at once
        Pipe             = 0x200,  // Use pipe interface instead of file
        DynamicPipe      = 0x1000  // Support for dynamic pipes
    }

    public class LogWriter
    {
        // ===== NESTED STRUCT: LogParams =====
        public struct LogParams
        {
            public LogFlags Flags;
            public ushort   DiskPageSize;
            public ushort   FlushDepth;
            public TimeSpan FlushTime;
        }

        // ===== NESTED STRUCT: LogInfo =====
        public struct LogInfo
        {
            public LogFlags Flags;
            public long     StartTransCounter;
            public long     LastTransCounter;
            public long     StoredTransactions;
            public long     LogSize;
            public long     PipeUsedSize;
            public int      LabelsCount;
            public uint     MaxParallelTrans;
            public uint     ExceededTransSlotsCount;
            public long     MaxTransactionSize;
        }

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

        // ===== LIFECYCLE METHODS =====
        public void Start(LogParams logParams);
        public void Stop();
        public void Terminate();
        public void Truncate();

        // ===== LOG MANAGEMENT METHODS =====
        public int SetLabel(string label);
        public bool SaveSnapshot(String databaseSnapshotFilePath);
        public void Flush();

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

Member Descriptions

LogFlags enum
Flags controlling transaction log behavior: Aligned (page-aligned records), Append (continue an existing log), Crc (CRC32 checksums), SyncInstantly/Timer/Count (flush policies), Iterable (enable LogReader iteration APIs), Pipe/DynamicPipe (pipe-based transport), and Restart (replace an existing active log).
LogParams struct
Configuration container for starting a transaction log: Flags (behavior modifiers), DiskPageSize (I/O block size), FlushDepth (max unflushed records), FlushTime (timer-based flush interval).
LogInfo struct (LogWriter)
Runtime statistics for an active log: transaction counters (Start/LastTransCounter), storage metrics (StoredTransactions, LogSize), pipe usage (PipeUsedSize), label count, MVCC parallelism stats (MaxParallelTrans, ExceededTransSlotsCount), and largest transaction size.
LogWriter(Connection, string)
Creates a transaction log writer for the specified database connection and file path. The database must be opened with the Database.Mode.TransactionLoggingSupport flag. In pipe mode, the filePath argument can be null.
Start(LogParams)
Begins transaction logging with the specified parameters. Subsequent transactions on this connection are recorded to the configured log target until Stop() or Terminate() is called.
Stop()
Stops logging and closes the active log target gracefully.
Terminate()
Forcibly terminates logging if the reader in pipe mode becomes unresponsive. Use with caution as it may leave the log in an incomplete state.
SetLabel(string)
Marks a named recovery point in the log at the current position. Returns a numeric label ID that can be used with LogReader.Apply(labelId) to replay transactions up to this point.
Truncate()
Clears the current log and restarts logging from scratch. Equivalent to calling Stop() followed by Start() with the same parameters.
SaveSnapshot(String)
Atomically saves a database snapshot to the specified file and truncates the log. The snapshot can later be loaded by Database.Open() when Database.Parameters.DatabaseSnapshotFilePath is set. Returns true on success.
Flush()
Forces immediate flushing of all buffered log data to disk, regardless of configured flush policies. Useful for ensuring durability before critical operations.
GetInfo()
Returns current statistics and configuration of the active log via the LogInfo structure.
Logging Requirements
The database must be created or opened with the Database.Mode.TransactionLoggingSupport flag. Logging is connection-specific: each LogWriter instance manages logging for its associated Connection.
Flush Policies
Configure durability vs. performance trade-offs via LogParams: SyncInstantly (maximum durability, lowest throughput), SyncTimer (periodic flushes), SyncCount (flush after N records), or combine flags for hybrid behavior.
Pipe Mode
When using LogFlags.Pipe or LogFlags.DynamicPipe, the log is written through the transaction log pipe interface instead of a regular file. This mode is used together with LogReader.IteratePipe(...) for real-time consumption of log records; in this case the writer is typically created with filePath = null.
Recovery Workflow
Typical file-based workflow: Start() -> perform transactions -> optionally call SetLabel("checkpoint") -> optionally call SaveSnapshot("backup.db") -> continue logging. On recovery, load the snapshot and use LogReader.Apply(...) to replay transactions to the desired point.