/// <summary> /// Attempts to apply configuration if possible. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="c">Configuration to apply.</param> /// <returns>True if the configuration applied.</returns> public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c) { if (c is not BinaryFileConfiguration cF || cF.Path != _config.Path) { return(ValueTask.FromResult(false)); } if (_config.UseGzipCompression != cF.UseGzipCompression) { var f = new MonitorBinaryFileOutput(_config.Path, cF.MaxCountPerFile, cF.UseGzipCompression); // If the initialization of the new file fails (should not happen), we fail to apply the configuration: // this handler will be Deactivated and another one will be created... and it may work. Who knows... if (!f.Initialize(m)) { return(ValueTask.FromResult(false)); } _file.Close(); _file = f; } else { _file.MaxCountPerFile = cF.MaxCountPerFile; } _config = cF; return(ValueTask.FromResult(true)); }
/// <summary> /// Initializes a new <see cref="BinaryFile"/> bound to its <see cref="BinaryFileConfiguration"/>. /// </summary> /// <param name="config">The configuration.</param> public BinaryFile(BinaryFileConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } _file = new MonitorBinaryFileOutput(config.Path, config.MaxCountPerFile, config.UseGzipCompression); _config = config; _countHousekeeping = _config.HousekeepingRate; }