@@ -156,22 +156,7 @@ private async Task ProcessCacheAsync(CancellationToken cancellationToken = defau
156156
157157 try
158158 {
159- #if ! NET461 && ! NETSTANDARD2_0
160- await
161- #endif
162- using var envelopeFile = File . OpenRead ( envelopeFilePath ) ;
163- using var envelope = await Envelope . DeserializeAsync ( envelopeFile , cancellationToken )
164- . ConfigureAwait ( false ) ;
165-
166- _options . LogDebug (
167- "Sending cached envelope: {0}" ,
168- envelope . TryGetEventId ( ) ) ;
169-
170- await _innerTransport . SendEnvelopeAsync ( envelope , cancellationToken ) . ConfigureAwait ( false ) ;
171-
172- _options . LogDebug (
173- "Successfully sent cached envelope: {0}" ,
174- envelope . TryGetEventId ( ) ) ;
159+ await InnerProcessCacheAsync ( cancellationToken , envelopeFilePath ) . ConfigureAwait ( false ) ;
175160 }
176161 catch ( Exception ex ) when ( IsRetryable ( ex ) )
177162 {
@@ -198,6 +183,30 @@ private async Task ProcessCacheAsync(CancellationToken cancellationToken = defau
198183 }
199184 }
200185
186+ private async Task InnerProcessCacheAsync ( CancellationToken cancellationToken , string envelopeFilePath )
187+ {
188+ var envelopeFile = File . OpenRead ( envelopeFilePath ) ;
189+ #if NET461 || NETSTANDARD2_0
190+ using ( envelopeFile )
191+ #else
192+ await using ( envelopeFile . ConfigureAwait ( false ) )
193+ #endif
194+ {
195+ using var envelope = await Envelope . DeserializeAsync ( envelopeFile , cancellationToken )
196+ . ConfigureAwait ( false ) ;
197+
198+ _options . LogDebug (
199+ "Sending cached envelope: {0}" ,
200+ envelope . TryGetEventId ( ) ) ;
201+
202+ await _innerTransport . SendEnvelopeAsync ( envelope , cancellationToken ) . ConfigureAwait ( false ) ;
203+
204+ _options . LogDebug (
205+ "Successfully sent cached envelope: {0}" ,
206+ envelope . TryGetEventId ( ) ) ;
207+ }
208+ }
209+
201210 // Loading an Envelope only reads the headers. The payload is read lazily, so we do Disk -> Network I/O
202211 // via stream directly instead of loading the whole file in memory. For that reason capturing an envelope
203212 // from disk could raise an IOException related to Disk I/O.
@@ -263,11 +272,12 @@ private async Task StoreToCacheAsync(
263272 EnsureFreeSpaceInCache ( ) ;
264273
265274 Directory . CreateDirectory ( _isolatedCacheDirectoryPath ) ;
266-
267- #if ! NET461 && ! NETSTANDARD2_0
268- await
275+ var stream = File . Create ( envelopeFilePath ) ;
276+ #if NET461 || NETSTANDARD2_0
277+ using ( stream )
278+ #else
279+ await using ( stream . ConfigureAwait ( false ) )
269280#endif
270- using ( var stream = File . Create ( envelopeFilePath ) )
271281 {
272282 await envelope . SerializeAsync ( stream , cancellationToken ) . ConfigureAwait ( false ) ;
273283 }
0 commit comments