// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections; using System.Collections.Generic; using System.Globalization; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal { public class ConnectionLogScope : IReadOnlyList> { private readonly string _connectionId; private string _cachedToString; public ConnectionLogScope(string connectionId) { _connectionId = connectionId; } public KeyValuePair this[int index] { get { if (index == 0) { return new KeyValuePair("ConnectionId", _connectionId); } throw new ArgumentOutOfRangeException(nameof(index)); } } public int Count => 1; public IEnumerator> GetEnumerator() { for (int i = 0; i < Count; ++i) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public override string ToString() { if (_cachedToString == null) { _cachedToString = string.Format( CultureInfo.InvariantCulture, "ConnectionId:{0}", _connectionId); } return _cachedToString; } } }