| | | 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 Microsoft.Extensions.Logging; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels.Framing |
| | | 8 | | { |
| | | 9 | | internal class ConnectionIdWrappingLogger : ILogger |
| | | 10 | | { |
| | | 11 | | private ILogger _innerLogger; |
| | | 12 | | private string _connectionId; |
| | | 13 | | |
| | 79 | 14 | | public ConnectionIdWrappingLogger(ILogger innerLogger, string connectionId) |
| | | 15 | | { |
| | 79 | 16 | | _innerLogger = innerLogger; |
| | 79 | 17 | | _connectionId = connectionId; |
| | 79 | 18 | | } |
| | 0 | 19 | | public IDisposable BeginScope<TState>(TState state) => _innerLogger.BeginScope(state); |
| | | 20 | | |
| | 14223 | 21 | | public bool IsEnabled(LogLevel logLevel) => _innerLogger.IsEnabled(logLevel); |
| | | 22 | | |
| | | 23 | | public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exce |
| | | 24 | | { |
| | 0 | 25 | | (TState state, string connectionId, Func<TState, Exception, string> origFormatter) newState = (state, _conne |
| | 0 | 26 | | _innerLogger.Log(logLevel, eventId, newState, exception, ConnectionIdFormatter<TState>); |
| | 0 | 27 | | } |
| | | 28 | | |
| | | 29 | | private static string ConnectionIdFormatter<TState>((TState state, string connectionId, Func<TState, Exception, |
| | | 30 | | { |
| | 0 | 31 | | var state = modifiedState.state; |
| | 0 | 32 | | var connectionId = modifiedState.connectionId; |
| | 0 | 33 | | var formatter = modifiedState.formatter; |
| | 0 | 34 | | var formattedString = formatter(state, exception); |
| | 0 | 35 | | return $"[{connectionId}] {formattedString}"; |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | } |