void IActivityMonitorBoundClient.SetMonitor(IActivityMonitorImpl?source, bool forceBuggyRemove)
 {
     if (source != null && _source != null)
     {
         throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException(this);
     }
     // Silently ignore null => null or monitor => same monitor.
     if (source != _source)
     {
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         Debug.Assert((source == null) != (_source == null));
         if ((_source = source) == null)
         {
             if (_file != null)
             {
                 _file.Close();
             }
             _file = null;
         }
         else
         {
             // If initialization failed, we let the file null: this monitor will not
             // work (the error will appear in the Critical errors) but this avoids
             // an exception to be thrown here.
             var f = new MonitorBinaryFileOutput(_path, _source.UniqueId, _maxCountPerFile, _useGzipCompression);
             if (f.Initialize(_source.InternalMonitor))
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
                 _file = f;
             }
         }
     }
 }
 void IActivityMonitorBoundClient.SetMonitor( IActivityMonitorImpl source, bool forceBuggyRemove )
 {
     if( source != null && _source != null ) throw ActivityMonitorClient.CreateMultipleRegisterOnBoundClientException( this );
     // Silently ignore null => null or monitor => same monitor.
     if( source != _source )
     {
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
         Debug.Assert( (source == null) != (_source == null) );
         if( (_source = source) == null )
         {
             if( _file != null ) _file.Close();
             _file = null;
         }
         else
         {
             // If initialization failed, we let the file null: this monitor will not
             // work (the error will appear in the Critical errors) but this avoids
             // an exception to be thrown here.
             var f = new MonitorBinaryFileOutput( _path, ((IUniqueId)_source).UniqueId, _maxCountPerFile, _useGzipCompression );
             if( f.Initialize( new SystemActivityMonitor( false, null ) ) )
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
                 _file = f;
             }
         }
     }
 }
 /// <summary>
 /// Opens this writer if it is not already opened.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public bool Open()
 {
     using (_source.ReentrancyAndConcurrencyLock())
     {
         if (_source == null)
         {
             throw new InvalidOperationException("CKMonWriterClient must be registered in an ActivityMonitor.");
         }
         if (_file != null)
         {
             return(true);
         }
         _file        = new MonitorBinaryFileOutput(_path, _source.UniqueId, _maxCountPerFile, _useGzipCompression);
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
     }
     using (SystemActivityMonitor.EnsureSystemClient(_source))
     {
         using (_source.ReentrancyAndConcurrencyLock())
         {
             if (_file.Initialize(_source))
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
             }
             else
             {
                 _file = null;
             }
         }
     }
     return(_file != null);
 }
 /// <summary>
 /// Opens this writer if it is not already opened.
 /// </summary>
 /// <returns>True on success, false otherwise.</returns>
 public bool Open()
 {
     using( _source.ReentrancyAndConcurrencyLock() )
     {
         if( _source == null ) throw new InvalidOperationException( "CKMonWriterClient must be registered in an ActivityMonitor." );
         if( _file != null ) return true;
         _file = new MonitorBinaryFileOutput( _path, _source.UniqueId, _maxCountPerFile, _useGzipCompression );
         _prevLogType = LogEntryType.None;
         _prevlogTime = DateTimeStamp.Unknown;
     }
     using( SystemActivityMonitor.EnsureSystemClient( _source ) )
     {
         using( _source.ReentrancyAndConcurrencyLock() )
         {
             if( _file.Initialize( _source ) )
             {
                 var g = _source.CurrentGroup;
                 _currentGroupDepth = g != null ? g.Depth : 0;
             }
             else _file = null;
         }
     }
     return _file != null;
 }