在查看参考源代码时,我看到WebSocketBase有很多日志记录语句,但没有明显的方法使其真正记录日志。我希望它可以帮助我诊断为什么我的客户机在从服务器传输文件期间不响应ping请求,那么我如何在这里启用日志记录呢?
WebSocketBase
ddrv8njm1#
如果您使用的是.Net Framework 4.x并使用app.config(如果您托管的是站点,则使用web.config),则可以配置名为“System.Net.WebSockets”的TraceSource,添加适当的开关级别和侦听器。
<configuration> <system.diagnostics> <sources> <source name="System.Net.WebSockets"> <listeners> <add name="System.Net"/> </listeners> </source> </sources> <switches> <add name="System.Net.WebSockets" value="Verbose"/> </switches> <sharedListeners> <add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" traceOutputOptions="ProcessId, DateTime" /> </sharedListeners> <trace autoflush="true"/> </system.diagnostics> </configuration>
这是使用Verbose开关(我在这里连接到ws://qa.sockets.stackexchange.com/)时可以预期的输出类型
ws://qa.sockets.stackexchange.com/
System.Net.WebSockets Verbose: 0 : [9428] Entering ClientWebSocket#45004109::.ctor() System.Net.WebSockets Verbose: 0 : [9428] Exiting ClientWebSocket#45004109::.ctor() System.Net.WebSockets Information: 0 : [9428] Associating ClientWebSocket#45004109 with HttpWebRequest#21454193 System.Net.WebSockets Information: 0 : [14188] Associating ClientWebSocket#45004109 with HttpWebResponse#12547953 System.Net.WebSockets Verbose: 0 : [14188] Entering InternalClientWebSocket#31364015::Initialize(ReceiveBufferSize: 16384, SendBufferSize: 16384, Protocols: , KeepAliveInterval: 00:00:30, innerStream: WebSocketConnectionStream#11429296, internalBuffer: WebSocketBuffer#41622463) System.Net.WebSockets Information: 0 : [14188] Associating InternalClientWebSocket#31364015 with WebSocketConnectionStream#11429296 System.Net.WebSockets Information: 0 : [14188] Associating InternalClientWebSocket#31364015 with WebSocketBuffer#41622463 System.Net.WebSockets Information: 0 : [14188] Associating WebSocketConnectionStream#11429296 with WebSocketConnection#28379535 System.Net.WebSockets Verbose: 0 : [14188] Exiting InternalClientWebSocket#31364015::Initialize() -> ReceiveBufferSize: 16384, SendBufferSize: 16384, Protocols: , KeepAliveInterval: 00:00:30, innerStream: WebSocketConnectionStream#11429296, internalBuffer: WebSocketBuffer#41622463 System.Net.WebSockets Information: 0 : [14188] Associating ClientWebSocket#45004109 with InternalClientWebSocket#31364015 System.Net.WebSockets Verbose: 0 : [14188] Entering InternalClientWebSocket#31364015::SendAsync(messageType: Text, endOfMessage: True) System.Net.WebSockets Verbose: 0 : [14188] Data from InternalClientWebSocket#31364015::SendAsync System.Net.WebSockets Verbose: 0 : [14188] 00000000 : 31 35 35 2D 71 75 65 73-74 69 6F 6E 73 2D 61 63 : 155-questions-ac System.Net.WebSockets Verbose: 0 : [14188] 00000010 : 74 69 76 65 : tive System.Net.WebSockets Verbose: 0 : [14188] Entering WebSocketConnectionStream#11429296::WriteAsync(offset: 16384, count: 26, cancellationToken.CanBeCanceled: True) System.Net.WebSockets Verbose: 0 : [14188] Entering WebSocketConnection#28379535::WriteAsync(offset: 16384, count: 26, cancellationToken.CanBeCanceled: True) System.Net.WebSockets Verbose: 0 : [14188] Exiting WebSocketConnection#28379535::WriteAsync() -> Boolean#1 System.Net.WebSockets Verbose: 0 : [3848] Entering WebSocketConnection#28379535::OnWriteCompleted(LastOperation: Send, SocketError: Success) System.Net.WebSockets Verbose: 0 : [3848] Data from WebSocketConnectionStream#11429296::WriteAsync System.Net.WebSockets Verbose: 0 : [3848] 00004000 : 81 94 2C 5F 76 52 1D 6A-43 7F 5D 2A 13 21 58 36 : ..,_vR.jC.]*.!X6 System.Net.WebSockets Verbose: 0 : [3848] 00004010 : 19 3C 5F 72 17 31 58 36-00 37 : .<_r.1X6.7 System.Net.WebSockets Verbose: 0 : [3848] Exiting WebSocketConnectionStream#11429296::WriteAsync() System.Net.WebSockets Verbose: 0 : [3848] Exiting InternalClientWebSocket#31364015::SendAsync() -> messageType: Text, endOfMessage: True System.Net.WebSockets Verbose: 0 : [3848] Entering InternalClientWebSocket#31364015::ReceiveAsync() System.Net.WebSockets Verbose: 0 : [3848] Entering WebSocketConnectionStream#11429296::ReadAsync(offset: 0, count: 16384, cancellationToken.CanBeCanceled: True) System.Net.WebSockets Verbose: 0 : [3848] Entering WebSocketConnection#28379535::ReadAsyncCore(offset: 0, count: 16384, cancellationToken.CanBeCanceled: True) System.Net.WebSockets Verbose: 0 : [3848] Exiting WebSocketConnection#28379535::ReadAsyncCore() -> Boolean#1 System.Net.WebSockets Verbose: 0 : [3848] Exiting WebSocketConnection#28379535::OnWriteCompleted() System.Net.WebSockets Verbose: 0 : [3848] Entering WebSocketConnection#28379535::OnReadCompleted(LastOperation: Receive, SocketError: Success) System.Net.WebSockets Verbose: 0 : [3848] Data from WebSocketConnectionStream#11429296::ReadAsync System.Net.WebSockets Verbose: 0 : [3848] 00000000 : 81 7E 03 11 7B 22 61 63-74 69 6F 6E 22 3A 22 31 : .~..{"action":"1 System.Net.WebSockets Verbose: 0 : [3848] 00000010 : 35 35 2D 71 75 65 73 74-69 6F 6E 73 2D 61 63 74 : 55-questions-act System.Net.WebSockets Verbose: 0 : [3848] 00000020 : 69 76 65 22 2C 22 64 61-74 61 22 3A 22 7B 5C 22 : ive","data":"{\" System.Net.WebSockets Verbose: 0 : [3848] 00000030 : 73 69 74 65 42 61 73 65-48 6F 73 74 41 64 64 72 : siteBaseHostAddr System.Net.WebSockets Verbose: 0 : [3848] 00000040 : 65 73 73 5C 22 3A 5C 22-73 74 61 63 6B 6F 76 65 : ess\":\"stackove System.Net.WebSockets Verbose: 0 : [3848] 00000050 : 72 66 6C 6F 77 2E 63 6F-6D 5C 22 2C 5C 22 69 64 : rflow.com\",\"id
1条答案
按热度按时间ddrv8njm1#
如果您使用的是.Net Framework 4.x并使用app.config(如果您托管的是站点,则使用web.config),则可以配置名为“System.Net.WebSockets”的TraceSource,添加适当的开关级别和侦听器。
这是使用Verbose开关(我在这里连接到
ws://qa.sockets.stackexchange.com/
)时可以预期的输出类型