PhysicalLogManager(LogManager.LoggerType LoggerType) { switch (LoggerType) { case LogManager.LoggerType.Inproc: { NativeLog.CreateLogManagerInproc(out this._NativeManager); _LoggerType = LogManager.LoggerType.Inproc; break; } case LogManager.LoggerType.Driver: { NativeLog.CreateLogManager(out this._NativeManager); _LoggerType = LogManager.LoggerType.Driver; break; } default: { throw new InvalidOperationException("Invalid LogManager.LoggerType"); } } }
InternalCreateAsync(LogManager.LoggerType logManagerType, CancellationToken cancellationToken) { Handle result = null; PhysicalLogManager newManager = null; Exception caughtException = null; await _Lock.WaitUntilSetAsync(cancellationToken).ConfigureAwait(false); try { if (_AppDomainPhysLogManager == null) { if (logManagerType == LogManager.LoggerType.Default) { // // Try to open driver first and if it fails then try inproc // try { newManager = new PhysicalLogManager(LogManager.LoggerType.Driver); await newManager.OpenAsync(cancellationToken).ConfigureAwait(false); } catch (System.IO.FileNotFoundException) { AppTrace.TraceSource.WriteInfo(TraceType, "InternalCreateAsync: FileNotFound returned when trying to open Driver. Proceeding with an Inproc log."); // // Don't fail if driver isn't loaded // newManager = null; } if (newManager == null) { // // Now try inproc // newManager = new PhysicalLogManager(LogManager.LoggerType.Inproc); await newManager.OpenAsync(cancellationToken).ConfigureAwait(false); } } else { // // Only try to open a specific log manager type // newManager = new PhysicalLogManager(logManagerType); await newManager.OpenAsync(cancellationToken).ConfigureAwait(false); } _LoggerType = newManager.GetLoggerType(); _AppDomainPhysLogManager = newManager; // No error during Open - } _NextHandleId++; result = new Handle(_NextHandleId); _Handles.Add(_NextHandleId, new WeakReference <Handle>(result, false)); result.IsOpen = true; newManager = null; } catch (Exception ex) { caughtException = ex; // for later re-throw if (result != null) { // Undo handle creation result.IsOpen = false; _Handles.Remove(result.Id); } if (newManager != null) { // Reverse creation of AppDomain singleton _AppDomainPhysLogManager = null; _LoggerType = LogManager.LoggerType.Unknown; } } finally { _Lock.Set(); } if (caughtException != null) { if (newManager != null) { // Finish reversal of creation of AppDomain singleton await newManager.CloseAsync(cancellationToken).ConfigureAwait(false); } throw caughtException; } return(result); }
/// <summary> /// Open access to the Logical Log Manager API /// </summary> /// <param name="logManagerType">Specifies the type of log manager to use</param> /// <param name="cancellationToken">Used to cancel the OpenAsync operation</param> /// <returns>Caller's ILogManager (Handle)</returns> public static Task <ILogManager> OpenAsync(LogManager.LoggerType logManagerType, CancellationToken cancellationToken) { return(InternalCreateAsync(logManagerType, cancellationToken)); }