Helper class that encapsulates temporary stream and final renaming for log entries streams. This currently handles only the maximum count of entries per file but this may be extended with options like "SubFolderMode" that can be based on current time (to group logs inside timed intermediate folders like one per day: 2014/01/12 or 2014-01/12, etc.).
Inheritance: MonitorFileOutputBase
 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;
             }
         }
     }
 }
Esempio n. 2
0
 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;
             }
         }
     }
 }
Esempio n. 3
0
 /// <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);
 }
Esempio n. 4
0
 /// <summary>
 /// Closes this writer if it <see cref="IsOpened"/>.
 /// It can be re-<see cref="Open"/>ed later.
 /// </summary>
 public void Close()
 {
     using (_source != null ? _source.ReentrancyAndConcurrencyLock() : null)
     {
         if (_file != null)
         {
             _file.Close();
         }
         _file = null;
     }
 }
Esempio n. 5
0
 /// <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;
 }
Esempio n. 6
0
 /// <summary>
 /// Closes this writer if it <see cref="IsOpened"/>.
 /// It can be re-<see cref="Open"/>ed later.
 /// </summary>
 public void Close()
 {
     using( _source != null ? _source.ReentrancyAndConcurrencyLock() : null )
     {
         if( _file != null ) _file.Close();
         _file = null;
     }
 }