Skip to content

Commit b7d2f0e

Browse files
authored
Remove trace interfaces from Kestrel transports (#37243)
1 parent cec67a8 commit b7d2f0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+419
-530
lines changed

src/Servers/Kestrel/Transport.Libuv/src/Internal/ILibuvTrace.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal partial class LibuvConnection : TransportConnection
3636
private bool _connectionClosed;
3737

3838
public LibuvConnection(UvStreamHandle socket,
39-
ILibuvTrace log,
39+
ILogger log,
4040
LibuvThread thread,
4141
IPEndPoint remoteEndPoint,
4242
IPEndPoint localEndPoint,
@@ -72,7 +72,7 @@ public LibuvConnection(UvStreamHandle socket,
7272
public PipeReader Output => Application.Input;
7373

7474
public LibuvOutputConsumer OutputConsumer { get; set; }
75-
private ILibuvTrace Log { get; }
75+
private ILogger Log { get; }
7676
private LibuvThread Thread { get; }
7777
public override MemoryPool<byte> MemoryPool => Thread.MemoryPool;
7878

@@ -114,7 +114,7 @@ private async Task StartCore()
114114
else
115115
{
116116
// This is unexpected.
117-
Log.ConnectionError(ConnectionId, ex);
117+
LibuvTrace.ConnectionError(Log, ConnectionId, ex);
118118

119119
inputError = ex;
120120
outputError = ex;
@@ -133,7 +133,7 @@ private async Task StartCore()
133133
Input.CancelPendingFlush();
134134

135135
// Send a FIN
136-
Log.ConnectionWriteFin(ConnectionId, inputError.Message);
136+
LibuvTrace.ConnectionWriteFin(Log, ConnectionId, inputError.Message);
137137

138138
// We're done with the socket now
139139
_socket.Dispose();
@@ -204,7 +204,7 @@ private void OnRead(UvStreamHandle handle, int status)
204204
}
205205
else if (status > 0)
206206
{
207-
Log.ConnectionRead(ConnectionId, status);
207+
LibuvTrace.ConnectionRead(Log, ConnectionId, status);
208208

209209
Input.Advance(status);
210210
var flushTask = Input.FlushAsync();
@@ -225,7 +225,7 @@ private void OnRead(UvStreamHandle handle, int status)
225225

226226
if (status == LibuvConstants.EOF)
227227
{
228-
Log.ConnectionReadFin(ConnectionId);
228+
LibuvTrace.ConnectionReadFin(Log, ConnectionId);
229229
}
230230
else
231231
{
@@ -262,15 +262,15 @@ private void FireConnectionClosed()
262262

263263
private async Task ApplyBackpressureAsync(ValueTask<FlushResult> flushTask)
264264
{
265-
Log.ConnectionPause(ConnectionId);
265+
LibuvTrace.ConnectionPause(Log, ConnectionId);
266266
_socket.ReadStop();
267267

268268
var result = await flushTask;
269269

270270
// If the reader isn't complete or cancelled then resume reading
271271
if (!result.IsCompleted && !result.IsCanceled)
272272
{
273-
Log.ConnectionResume(ConnectionId);
273+
LibuvTrace.ConnectionResume(Log, ConnectionId);
274274
StartReading();
275275
}
276276
}
@@ -299,13 +299,13 @@ private Exception LogAndWrapReadError(UvException uvError)
299299
else if (LibuvConstants.IsConnectionReset(uvError.StatusCode))
300300
{
301301
// Log connection resets at a lower (Debug) level.
302-
Log.ConnectionReset(ConnectionId);
302+
LibuvTrace.ConnectionReset(Log, ConnectionId);
303303
return new ConnectionResetException(uvError.Message, uvError);
304304
}
305305
else
306306
{
307307
// This is unexpected.
308-
Log.ConnectionError(ConnectionId, uvError);
308+
LibuvTrace.ConnectionError(Log, ConnectionId, uvError);
309309
return new IOException(uvError.Message, uvError);
310310
}
311311
}

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnectionListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public LibuvConnectionListener(LibuvFunctions uv, LibuvTransportContext context,
3939
public List<LibuvThread> Threads { get; } = new List<LibuvThread>();
4040

4141
public IHostApplicationLifetime AppLifetime => TransportContext.AppLifetime;
42-
public ILibuvTrace Log => TransportContext.Log;
42+
public ILogger Log => TransportContext.Log;
4343

4444
#pragma warning disable CS0618
4545
public LibuvTransportOptions TransportOptions => TransportContext.Options;

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTrace.cs renamed to src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvLog.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,42 @@
66

77
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
88
{
9-
internal partial class LibuvTrace : ILibuvTrace
9+
internal static partial class LibuvTrace
1010
{
11-
private readonly ILogger _logger;
12-
13-
public LibuvTrace(ILogger logger)
14-
{
15-
_logger = logger;
16-
}
17-
18-
public void ConnectionRead(string connectionId, int count)
11+
public static void ConnectionRead(ILogger logger, string connectionId, int count)
1912
{
2013
// Don't log for now since this could be *too* verbose.
2114
// Reserved: Event ID 3
2215
}
2316

2417
[LoggerMessage(6, LogLevel.Debug, @"Connection id ""{ConnectionId}"" received FIN.", EventName = nameof(ConnectionReadFin))]
25-
public partial void ConnectionReadFin(string connectionId);
18+
public static partial void ConnectionReadFin(ILogger logger, string connectionId);
2619

2720
[LoggerMessage(7, LogLevel.Debug, @"Connection id ""{ConnectionId}"" sending FIN because: ""{Reason}""", EventName = nameof(ConnectionWriteFin))]
28-
public partial void ConnectionWriteFin(string connectionId, string reason);
21+
public static partial void ConnectionWriteFin(ILogger logger, string connectionId, string reason);
2922

30-
public void ConnectionWrite(string connectionId, int count)
23+
public static void ConnectionWrite(ILogger logger, string connectionId, int count)
3124
{
3225
// Don't log for now since this could be *too* verbose.
3326
// Reserved: Event ID 11
3427
}
3528

36-
public void ConnectionWriteCallback(string connectionId, int status)
29+
public static void ConnectionWriteCallback(ILogger logger, string connectionId, int status)
3730
{
3831
// Don't log for now since this could be *too* verbose.
3932
// Reserved: Event ID 12
4033
}
4134

4235
[LoggerMessage(14, LogLevel.Debug, @"Connection id ""{ConnectionId}"" communication error.", EventName = nameof(ConnectionError))]
43-
public partial void ConnectionError(string connectionId, Exception ex);
36+
public static partial void ConnectionError(ILogger logger, string connectionId, Exception ex);
4437

4538
[LoggerMessage(19, LogLevel.Debug, @"Connection id ""{ConnectionId}"" reset.", EventName = nameof(ConnectionReset))]
46-
public partial void ConnectionReset(string connectionId);
39+
public static partial void ConnectionReset(ILogger logger, string connectionId);
4740

4841
[LoggerMessage(4, LogLevel.Debug, @"Connection id ""{ConnectionId}"" paused.", EventName = nameof(ConnectionPause))]
49-
public partial void ConnectionPause(string connectionId);
42+
public static partial void ConnectionPause(ILogger logger, string connectionId);
5043

5144
[LoggerMessage(5, LogLevel.Debug, @"Connection id ""{ConnectionId}"" resumed.", EventName = nameof(ConnectionResume))]
52-
public partial void ConnectionResume(string connectionId);
53-
54-
public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);
55-
56-
public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);
57-
58-
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
59-
=> _logger.Log(logLevel, eventId, state, exception, formatter);
45+
public static partial void ConnectionResume(ILogger logger, string connectionId);
6046
}
6147
}

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvOutputConsumer.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO.Pipelines;
66
using System.Threading.Tasks;
77
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;
8+
using Microsoft.Extensions.Logging;
89

910
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
1011
{
@@ -13,15 +14,15 @@ internal class LibuvOutputConsumer
1314
private readonly LibuvThread _thread;
1415
private readonly UvStreamHandle _socket;
1516
private readonly string _connectionId;
16-
private readonly ILibuvTrace _log;
17+
private readonly ILogger _log;
1718
private readonly PipeReader _pipe;
1819

1920
public LibuvOutputConsumer(
2021
PipeReader pipe,
2122
LibuvThread thread,
2223
UvStreamHandle socket,
2324
string connectionId,
24-
ILibuvTrace log)
25+
ILogger log)
2526
{
2627
_pipe = pipe;
2728
_thread = thread;
@@ -97,7 +98,7 @@ private void LogWriteInfo(int status, Exception error)
9798
{
9899
if (error == null)
99100
{
100-
_log.ConnectionWriteCallback(_connectionId, status);
101+
LibuvTrace.ConnectionWriteCallback(_log, _connectionId, status);
101102
}
102103
else
103104
{
@@ -108,11 +109,11 @@ private void LogWriteInfo(int status, Exception error)
108109
}
109110
else if (LibuvConstants.IsConnectionReset(status))
110111
{
111-
_log.ConnectionReset(_connectionId);
112+
LibuvTrace.ConnectionReset(_log, _connectionId);
112113
}
113114
else
114115
{
115-
_log.ConnectionError(_connectionId, error);
116+
LibuvTrace.ConnectionError(_log, _connectionId, error);
116117
}
117118
}
118119
}

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ internal class LibuvThread : PipeScheduler
3838
private bool _stopImmediate;
3939
private bool _initCompleted;
4040
private Exception _closeError;
41-
private readonly ILibuvTrace _log;
41+
private readonly ILogger _log;
4242

4343
public LibuvThread(LibuvFunctions libuv, LibuvTransportContext libuvTransportContext, int maxLoops = 8)
4444
: this(libuv, libuvTransportContext.AppLifetime, libuvTransportContext.Options.MemoryPoolFactory(), libuvTransportContext.Log, maxLoops)
4545
{
4646
}
4747

48-
public LibuvThread(LibuvFunctions libuv, IHostApplicationLifetime appLifetime, MemoryPool<byte> pool, ILibuvTrace log, int maxLoops = 8)
48+
public LibuvThread(LibuvFunctions libuv, IHostApplicationLifetime appLifetime, MemoryPool<byte> pool, ILogger log, int maxLoops = 8)
4949
{
5050
_libuv = libuv;
5151
_appLifetime = appLifetime;

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.Extensions.Hosting;
5+
using Microsoft.Extensions.Logging;
56

67
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
78
{
@@ -13,6 +14,6 @@ internal class LibuvTransportContext
1314

1415
public IHostApplicationLifetime AppLifetime { get; set; }
1516

16-
public ILibuvTrace Log { get; set; }
17+
public ILogger Log { get; set; }
1718
}
1819
}

src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvTransportFactory.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public LibuvTransportFactory(
3737
}
3838

3939
var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv");
40-
var trace = new LibuvTrace(logger);
4140

4241
#pragma warning disable CS0618
4342
var threadCount = options.Value.ThreadCount;
@@ -52,19 +51,19 @@ public LibuvTransportFactory(
5251

5352
if (!LibuvConstants.ECONNRESET.HasValue)
5453
{
55-
trace.LogWarning("Unable to determine ECONNRESET value on this platform.");
54+
logger.LogWarning("Unable to determine ECONNRESET value on this platform.");
5655
}
5756

5857
if (!LibuvConstants.EADDRINUSE.HasValue)
5958
{
60-
trace.LogWarning("Unable to determine EADDRINUSE value on this platform.");
59+
logger.LogWarning("Unable to determine EADDRINUSE value on this platform.");
6160
}
6261

6362
_baseTransportContext = new LibuvTransportContext
6463
{
6564
Options = options.Value,
6665
AppLifetime = applicationLifetime,
67-
Log = trace,
66+
Log = logger,
6867
};
6968
}
7069

src/Servers/Kestrel/Transport.Libuv/src/Internal/Listener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Listener(LibuvTransportContext transportContext) : base(transportContext)
2525

2626
protected UvStreamHandle ListenSocket { get; private set; }
2727

28-
public ILibuvTrace Log => TransportContext.Log;
28+
public ILogger Log => TransportContext.Log;
2929

3030
public Task StartAsync(
3131
EndPoint endPoint,
@@ -184,7 +184,7 @@ private void OnConnection(UvStreamHandle listenSocket, int status)
184184
}
185185
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
186186
{
187-
Log.ConnectionReset("(null)");
187+
LibuvTrace.ConnectionReset(Log, "(null)");
188188
acceptSocket?.Dispose();
189189
}
190190
catch (UvException ex)

src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected internal void HandleConnection(UvStreamHandle socket)
102102
}
103103
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
104104
{
105-
TransportContext.Log.ConnectionReset("(null)");
105+
LibuvTrace.ConnectionReset(TransportContext.Log, "(null)");
106106
socket.Dispose();
107107
return;
108108
}

src/Servers/Kestrel/Transport.Libuv/src/Internal/ListenerSecondary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ListenerSecondary(LibuvTransportContext transportContext) : base(transpor
3030

3131
UvPipeHandle DispatchPipe { get; set; }
3232

33-
public ILibuvTrace Log => TransportContext.Log;
33+
public ILogger Log => TransportContext.Log;
3434

3535
public Task StartAsync(
3636
string pipeName,
@@ -156,7 +156,7 @@ private void ReadStartCallback(UvStreamHandle handle, int status)
156156
}
157157
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
158158
{
159-
Log.ConnectionReset("(null)");
159+
LibuvTrace.ConnectionReset(Log, "(null)");
160160
acceptSocket.Dispose();
161161
}
162162
catch (UvException ex)

src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvAsyncHandle.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Threading;
7+
using Microsoft.Extensions.Logging;
78

89
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking
910
{
@@ -15,7 +16,7 @@ internal class UvAsyncHandle : UvHandle
1516
private Action _callback;
1617
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
1718

18-
public UvAsyncHandle(ILibuvTrace logger) : base(logger)
19+
public UvAsyncHandle(ILogger logger) : base(logger)
1920
{
2021
}
2122

src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvConnectRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class UvConnectRequest : UvRequest
1616
private Action<UvConnectRequest, int, UvException, object> _callback;
1717
private object _state;
1818

19-
public UvConnectRequest(ILibuvTrace logger) : base (logger)
19+
public UvConnectRequest(ILogger logger) : base (logger)
2020
{
2121
}
2222

src/Servers/Kestrel/Transport.Libuv/src/Internal/Networking/UvHandle.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Threading;
7+
using Microsoft.Extensions.Logging;
78

89
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking
910
{
@@ -12,7 +13,7 @@ internal abstract class UvHandle : UvMemory
1213
private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle);
1314
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
1415

15-
protected UvHandle(ILibuvTrace logger) : base (logger)
16+
protected UvHandle(ILogger logger) : base (logger)
1617
{
1718
}
1819

0 commit comments

Comments
 (0)