1- using Microsoft . Extensions . Logging ;
2- using NetCoreStack . WebSockets . Interfaces ;
3- using System ;
1+ using System ;
42using System . IO ;
53using System . Net . WebSockets ;
64using System . Threading ;
@@ -29,17 +27,24 @@ private async Task InternalReceiveAsync()
2927 {
3028 if ( result . MessageType == WebSocketMessageType . Text )
3129 {
32- var context = result . ToContext ( buffer ) ;
33- if ( context . Command == WebSocketCommands . Handshake )
30+ try
3431 {
35- _context . ConnectionId = context . Value ? . ToString ( ) ;
36- _handshakeCallback ? . Invoke ( _context . ConnectionId ) ;
37- }
32+ var context = result . ToContext ( buffer ) ;
33+ if ( context . Command == WebSocketCommands . Handshake )
34+ {
35+ _context . ConnectionId = context . Value ? . ToString ( ) ;
36+ _handshakeCallback ? . Invoke ( _context . ConnectionId ) ;
37+ }
3838
39- var _invocators = _context . InvocatorRegistry . GetInvocators ( context , _context . Options ) ;
40- foreach ( var invoker in _invocators )
39+ var _invocators = _context . InvocatorRegistry . GetInvocators ( context , _context . Options ) ;
40+ foreach ( var invoker in _invocators )
41+ {
42+ await invoker . InvokeAsync ( context ) ;
43+ }
44+ }
45+ catch ( Exception ex )
4146 {
42- await invoker . InvokeAsync ( context ) ;
47+ LogHelper . Log ( _context , ex ) ;
4348 }
4449 result = await _context . WebSocket . ReceiveAsync ( new ArraySegment < byte > ( buffer ) , CancellationToken . None ) ;
4550 }
@@ -77,11 +82,7 @@ private async Task InternalReceiveAsync()
7782 }
7883 catch ( Exception ex )
7984 {
80- var logger = _context . LoggerFactory . CreateLogger < WebSocketReceiver > ( ) ;
81- logger . LogDebug ( new EventId ( ( int ) WebSocketState . Aborted ,
82- nameof ( WebSocketState . Aborted ) ) ,
83- ex , "WebSocket transport exception!" ,
84- _context . Options ) ;
85+ LogHelper . Log ( _context , ex ) ;
8586 }
8687 result = await _context . WebSocket . ReceiveAsync ( new ArraySegment < byte > ( buffer ) , CancellationToken . None ) ;
8788 }
@@ -98,11 +99,7 @@ public async Task ReceiveAsync()
9899 }
99100 catch ( Exception ex )
100101 {
101- var logger = _context . LoggerFactory . CreateLogger < ConnectionManager > ( ) ;
102- logger . LogDebug ( new EventId ( ( int ) WebSocketState . Aborted , nameof ( WebSocketState . Aborted ) ) ,
103- ex ,
104- "WebSocket connection end!" ,
105- _context . Options ) ;
102+ LogHelper . Log ( _context , ex ) ;
106103 }
107104 finally
108105 {
0 commit comments