Esempio n. 1
0
        public static IBinaryLog CreateFile(string filename, long headerSize)
        {
            if (headerSize % 16 != 0)
            {
                throw new ArgumentException();
            }

            using (var stream = new FileStream(filename, FileMode.CreateNew))
                using (var writer = new StreamBinaryWriter(stream))
                {
                    writer.WriteInt64(DateTime.UtcNow.Ticks);
                    writer.WriteInt64(headerSize);
                    stream.SetLength(headerSize);
                }

            return(OpenFile(filename));
        }
Esempio n. 2
0
        public BinaryLogRecord Add(byte[] record)
        {
            var hpos = _recCount * BinaryLogRecord.StampSize;

            if (hpos >= _contentPosition)
            {
                throw new LogFileOverflowException(_filename);
            }

            var rec = new BinaryLogRecord(DateTime.UtcNow, record);

            _headerWriter.Position = hpos;
            _headerWriter.WriteInt64(rec.timestamp.Ticks);
            _headerWriter.WriteInt64(_contentStream.Length);
            _contentWriter.Position = _contentStream.Length;
            _contentWriter.WriteByteArray(rec.content);
            _recCount++;
            return(rec);
        }