/// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            if (IsDisposed)
            {
                const string errmsg = "Tried to dispose of already-disposed object `{0}`.";
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat(errmsg, this);
                }
                Debug.Fail(string.Format(errmsg, this));
                return;
            }

            _isDisposed = true;

            GC.SuppressFinalize(this);

            // Flush out the writer to the file
            if (_filePath != null)
            {
                var bytes = _writer.GetBufferCopy();

                // Write to a temp file first
                var tempFile = new TempFile();
                File.WriteAllBytes(tempFile.FilePath, bytes);

                // Move to the actual destination
                tempFile.MoveTo(_filePath);
            }
        }