| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.Globalization; |
| | | 8 | | using System.Text; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Channels |
| | | 11 | | { |
| | | 12 | | // Copied from Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionLogScope |
| | | 13 | | // This class is used to add the connection ID to the log scope in a lightweight way. |
| | | 14 | | // A Dictionary is too heavy weight for this simple usage. |
| | | 15 | | internal sealed class ConnectionLogScope : IReadOnlyList<KeyValuePair<string, object>> |
| | | 16 | | { |
| | | 17 | | private readonly string _connectionId; |
| | | 18 | | |
| | | 19 | | private string _cachedToString; |
| | | 20 | | |
| | 0 | 21 | | public ConnectionLogScope(string connectionId) |
| | | 22 | | { |
| | 0 | 23 | | _connectionId = connectionId; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public KeyValuePair<string, object> this[int index] |
| | | 27 | | { |
| | | 28 | | get |
| | | 29 | | { |
| | 0 | 30 | | if (index == 0) |
| | | 31 | | { |
| | 0 | 32 | | return new KeyValuePair<string, object>("ConnectionId", _connectionId); |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | throw new ArgumentOutOfRangeException(nameof(index)); |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | public int Count => 1; |
| | | 40 | | |
| | | 41 | | public IEnumerator<KeyValuePair<string, object>> GetEnumerator() |
| | | 42 | | { |
| | 0 | 43 | | for (int i = 0; i < Count; ++i) |
| | | 44 | | { |
| | 0 | 45 | | yield return this[i]; |
| | | 46 | | } |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | IEnumerator IEnumerable.GetEnumerator() |
| | | 50 | | { |
| | 0 | 51 | | return GetEnumerator(); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | public override string ToString() |
| | | 55 | | { |
| | 0 | 56 | | if (_cachedToString == null) |
| | | 57 | | { |
| | 0 | 58 | | _cachedToString = string.Format( |
| | 0 | 59 | | CultureInfo.InvariantCulture, |
| | 0 | 60 | | "ConnectionId:{0}", |
| | 0 | 61 | | _connectionId); |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | return _cachedToString; |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |