public LogicalLogInfo(LogicalLog logicalLog, IPhysicalLogStream underlyingStream)
 {
     this.LogicalLog       = new WeakReference <LogicalLog>(logicalLog);
     this.UnderlyingStream = underlyingStream;
 }
            OnOpenLogicalLogAsync(
                Handle owningHandle,
                Guid logicalLogId,
                string traceType,
                CancellationToken cancellationToken)
            {
                await this._PhysicalLogLock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false);

                try
                {
                    LogicalLog     logicalLog = null;
                    LogicalLogInfo llInfo;

                    if ((this._LogicalLogs.TryGetValue(logicalLogId, out llInfo) == false) ||
                        (llInfo.LogicalLog.TryGetTarget(out logicalLog) == false))
                    {
                        // LLog has not been opened or created - attempt to open it
                        IPhysicalLogStream underlyingStream = null;
                        var       retries    = 0;
                        const int retryLimit = 3;

                        do
                        {
                            try
                            {
                                underlyingStream = await this._Container.OpenPhysicalLogStreamAsync(
                                    logicalLogId,
                                    cancellationToken).ConfigureAwait(false);

                                retries = retryLimit;
                            }
                            catch (System.IO.FileLoadException ex)
                            {
                                retries++;
                                if ((ex.HResult != unchecked ((int)0x80070020)) ||
                                    (retries == retryLimit))
                                {
                                    throw;
                                }
                            }
                        } while (retries < retryLimit);

                        Exception  caughtException = null;
                        LogicalLog newLogicalLog   = null;
                        try
                        {
                            newLogicalLog = new LogicalLog(this, owningHandle.Id, logicalLogId, underlyingStream, traceType);

                            this._LogicalLogs.Add(logicalLogId, new LogicalLogInfo(newLogicalLog, underlyingStream));

                            newLogicalLog.IsOpen = true;

                            await newLogicalLog.OnRecoverAsync(cancellationToken).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            // Cause clean up failed create
                            caughtException = ex;
                        }

                        if (caughtException != null)
                        {
                            // clean up failed create and forward the causing exception
                            if (newLogicalLog != null)
                            {
                                newLogicalLog.IsOpen = false;
                                this._LogicalLogs.Remove(logicalLogId);
                            }

                            // TODO: Consider adding trace output when secondary exceptions occur
                            try
                            {
                                await underlyingStream.CloseAsync(cancellationToken).ConfigureAwait(false);
                            }
                            catch
                            {
                            }
                            throw caughtException;
                        }

                        return(newLogicalLog);
                    }
                    else
                    {
                        // Already open - fault - only exclusive opens supported
                        throw new UnauthorizedAccessException();
                    }
                }
                finally
                {
                    this._PhysicalLogLock.Set();
                }
            }