internal ISection GetOrCreateSection(string[] chain, params object[] args) { if (chain == null) { throw new ArgumentNullException(nameof(chain)); } if (chain.Length == 0) { throw new ArgumentException("empty collection", nameof(chain)); } for (int i = 0; i < chain.Length; i++) { if (string.IsNullOrWhiteSpace(chain[i])) { throw new ArgumentException("at least one of chain items is null or whitespace", nameof(chain)); } } var queue = _pool.GetOrAdd(chain, k => new ConcurrentQueue <Section>()); if (!queue.TryDequeue(out Section section)) { ITimeMeasure timeMeasure = _factory.CreateTimeMeasure() ?? throw new InvalidOperationException($"factory returns null {nameof(IReportWriter)}"); section = new Section(this, timeMeasure, _traceWriter, chain, queue); _reportWriter.Add(section); } section.Enter(args); return(section); }