internal LogManagementAsyncResult(LogStore logStore) : base(null, null) { this.logStore = logStore; this.notification = new CLFS_MGMT_NOTIFICATION(); this.handleLogFullCallbackList = null; }
public LogRecordSequence( LogStore logStore, int bufferSize, int bufferCount) { if (logStore == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("logStore")); } if (bufferSize <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("bufferSize")); } if (bufferCount <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("bufferCount")); } this.store = logStore; this.ownStore = false; this.bufferSize = GetBufferSize(bufferSize); this.writeBufferCount = bufferCount; }
// The LogStore constructor will demand full trust, so we don't have to. public LogRecordSequence( string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, int bufferCount, FileSecurity fileSecurity) { if (bufferSize <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("bufferSize")); } if (bufferCount <= 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("bufferCount")); } this.store = new LogStore(path, mode, access, share, fileSecurity); this.ownStore = true; this.bufferSize = GetBufferSize(bufferSize); this.writeBufferCount = bufferCount; }
// The LogStore constructor will demand full trust, so we don't have to. public LogRecordSequence( string path, FileMode mode) { this.store = new LogStore(path, mode); this.ownStore = true; this.bufferSize = GetBufferSize(DefaultBufferSize); this.writeBufferCount = DefaultWriteBufferCount; }
public LogRecordSequence(LogStore logStore) { if (logStore == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentNull("logStore")); } this.store = logStore; this.ownStore = false; this.bufferSize = GetBufferSize(DefaultBufferSize); this.writeBufferCount = DefaultWriteBufferCount; }
internal LogArchiveSnapshot(LogStore store, ulong lsnLow, ulong lsnHigh) { StringBuilder baseLogFileName = new StringBuilder(MaxFileNameLength); int actualLength; ulong baseLogFileOffset; ulong baseLogFileLength; ulong lsnBase; ulong lsnLast; ulong lsnArchiveTail; SafeArchiveContext archiveContext = null; try { while (!UnsafeNativeMethods.PrepareLogArchive( store.Handle, baseLogFileName, baseLogFileName.Capacity, ref lsnLow, ref lsnHigh, out actualLength, out baseLogFileOffset, out baseLogFileLength, out lsnBase, out lsnLast, out lsnArchiveTail, out archiveContext)) { baseLogFileName.EnsureCapacity(actualLength + 1); } this.archiveTail = new SequenceNumber(lsnArchiveTail); this.baseSequenceNumber = new SequenceNumber(lsnBase); this.lastSequenceNumber = new SequenceNumber(lsnLast); List <FileRegion> regions = new List <FileRegion>(); byte[] readBuffer = new byte[checked ((uint)baseLogFileLength)]; uint actualDataLength = 0; unsafe { fixed(byte *pbReadBuffer = readBuffer) { UnsafeNativeMethods.ReadLogArchiveMetadata( archiveContext, 0, readBuffer.Length, pbReadBuffer, out actualDataLength); } } byte[] baseFileData; if (actualDataLength == (uint)baseLogFileLength) { baseFileData = readBuffer; } else { baseFileData = new byte[actualDataLength]; Array.Copy(readBuffer, baseFileData, baseFileData.Length); } regions.Add(new FileRegion((long)baseLogFileLength, baseLogFileName.ToString(), (long)baseLogFileOffset, baseFileData)); CLFS_ARCHIVE_DESCRIPTOR descriptor = new CLFS_ARCHIVE_DESCRIPTOR(); while (true) { int returnedCount; if (!UnsafeNativeMethods.GetNextLogArchiveExtentSingle( archiveContext, ref descriptor, out returnedCount)) { break; } if (returnedCount < 1) { break; } long start = checked ((long)descriptor.coffLow); long length = checked ((long)(descriptor.coffHigh - descriptor.coffLow)); string fileName = descriptor.infoContainer.GetActualFileName(store.Handle); FileInfo containerInfo; containerInfo = new FileInfo(fileName); regions.Add(new FileRegion(containerInfo.Length, fileName, start, length)); } this.regions = regions.AsReadOnly(); } finally { if (archiveContext != null && !archiveContext.IsInvalid) { archiveContext.Close(); } } }
internal LogExtentCollection(LogStore store) { this.store = store; }
internal LogArchiveSnapshot(LogStore store, ulong lsnLow, ulong lsnHigh) { StringBuilder baseLogFileName = new StringBuilder(MaxFileNameLength); int actualLength; ulong baseLogFileOffset; ulong baseLogFileLength; ulong lsnBase; ulong lsnLast; ulong lsnArchiveTail; SafeArchiveContext archiveContext = null; try { while (!UnsafeNativeMethods.PrepareLogArchive( store.Handle, baseLogFileName, baseLogFileName.Capacity, ref lsnLow, ref lsnHigh, out actualLength, out baseLogFileOffset, out baseLogFileLength, out lsnBase, out lsnLast, out lsnArchiveTail, out archiveContext)) { baseLogFileName.EnsureCapacity(actualLength + 1); } this.archiveTail = new SequenceNumber(lsnArchiveTail); this.baseSequenceNumber = new SequenceNumber(lsnBase); this.lastSequenceNumber = new SequenceNumber(lsnLast); List<FileRegion> regions = new List<FileRegion>(); byte[] readBuffer = new byte[checked((uint)baseLogFileLength)]; uint actualDataLength = 0; unsafe { fixed (byte* pbReadBuffer = readBuffer) { UnsafeNativeMethods.ReadLogArchiveMetadata( archiveContext, 0, readBuffer.Length, pbReadBuffer, out actualDataLength); } } byte[] baseFileData; if (actualDataLength == (uint)baseLogFileLength) { baseFileData = readBuffer; } else { baseFileData = new byte[actualDataLength]; Array.Copy(readBuffer, baseFileData, baseFileData.Length); } regions.Add(new FileRegion((long)baseLogFileLength, baseLogFileName.ToString(), (long)baseLogFileOffset, baseFileData)); CLFS_ARCHIVE_DESCRIPTOR descriptor = new CLFS_ARCHIVE_DESCRIPTOR(); while (true) { int returnedCount; if (!UnsafeNativeMethods.GetNextLogArchiveExtentSingle( archiveContext, ref descriptor, out returnedCount)) { break; } if (returnedCount < 1) break; long start = checked((long)descriptor.coffLow); long length = checked((long)(descriptor.coffHigh - descriptor.coffLow)); string fileName = descriptor.infoContainer.GetActualFileName(store.Handle); FileInfo containerInfo; containerInfo = new FileInfo(fileName); regions.Add(new FileRegion(containerInfo.Length, fileName, start, length)); } this.regions = regions.AsReadOnly(); } finally { if (archiveContext != null && !archiveContext.IsInvalid) { archiveContext.Close(); } } }
/// <summary> /// Initializes a new instance of the <see cref="Logger"/> class. /// </summary> /// <param name="basePath"> /// The base path where the log files are resided. /// </param> /// <param name="baseName"> /// The base name of the log files. /// </param> /// <param name="extentSize"> /// Size of each log extent in bytes. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="basePath"/> is null, or <paramref name="baseName"/> is null. /// </exception> public Logger(string basePath, string baseName, int extentSize) { if (string.IsNullOrEmpty(basePath)) { throw new ArgumentNullException("basePath"); } if (string.IsNullOrEmpty(baseName)) { throw new ArgumentNullException("baseName"); } // If the base path doesn't exist, create it. if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } string fullPath = Path.Combine(basePath, baseName); try { _store = new LogStore(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); } catch (PlatformNotSupportedException) { AutomaticDisable = true; return; } _sequence = new LogRecordSequence(_store); _sequence.RetryAppend = true; if (_store.Extents.Count == 0) { _store.Extents.Add(fullPath, extentSize); } }