File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Src/Notion.Client/RestClient Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Net . Http ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+
6+ namespace Notion . Client
7+ {
8+ public class LoggingHandler : DelegatingHandler
9+ {
10+ protected override async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
11+ {
12+ Log . Trace ( "Request: {request}" , request ) ;
13+
14+ try
15+ {
16+ var response = await base . SendAsync ( request , cancellationToken ) ;
17+
18+ Log . Trace ( "Response: {response}" , response ) ;
19+
20+ return response ;
21+ }
22+ catch ( Exception ex )
23+ {
24+ Log . Error ( ex , "Failed to get response: {exception}" , ex ) ;
25+ throw ;
26+ }
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change @@ -153,7 +153,8 @@ private HttpClient EnsureHttpClient()
153153 {
154154 if ( _httpClient == null )
155155 {
156- _httpClient = new HttpClient ( ) ;
156+ var pipeline = new LoggingHandler ( ) { InnerHandler = new HttpClientHandler ( ) } ;
157+ _httpClient = new HttpClient ( pipeline ) ;
157158 _httpClient . BaseAddress = new Uri ( _options . BaseUrl ) ;
158159 }
159160
You can’t perform that action at this time.
0 commit comments