@@ -176,17 +176,8 @@ internal class PartBufferManager : IPartBufferManager
176176
177177 #endregion
178178
179- #region Logger
179+ private readonly Logger _logger = Logger . GetLogger ( typeof ( PartBufferManager ) ) ;
180180
181- private Logger Logger
182- {
183- get
184- {
185- return Logger . GetLogger ( typeof ( TransferUtility ) ) ;
186- }
187- }
188-
189- #endregion
190181
191182 /// <summary>
192183 /// Initializes a new instance of the <see cref="PartBufferManager"/> class.
@@ -205,7 +196,7 @@ public PartBufferManager(BufferedDownloadConfiguration config)
205196 ) ;
206197 _partAvailable = new AutoResetEvent ( false ) ;
207198
208- Logger . DebugFormat ( "PartBufferManager initialized with MaxInMemoryParts={0}" , config . MaxInMemoryParts ) ;
199+ _logger . DebugFormat ( "PartBufferManager initialized with MaxInMemoryParts={0}" , config . MaxInMemoryParts ) ;
209200 }
210201
211202 /// <inheritdoc/>
@@ -236,12 +227,12 @@ public async Task WaitForBufferSpaceAsync(CancellationToken cancellationToken)
236227 ThrowIfDisposed ( ) ;
237228
238229 var availableBefore = _bufferSpaceAvailable . CurrentCount ;
239- Logger . DebugFormat ( "PartBufferManager: Waiting for buffer space (Available slots before wait: {0})" , availableBefore ) ;
230+ _logger . DebugFormat ( "PartBufferManager: Waiting for buffer space (Available slots before wait: {0})" , availableBefore ) ;
240231
241232 await _bufferSpaceAvailable . WaitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
242233
243234 var availableAfter = _bufferSpaceAvailable . CurrentCount ;
244- Logger . DebugFormat ( "PartBufferManager: Buffer space acquired (Available slots after acquire: {0})" , availableAfter ) ;
235+ _logger . DebugFormat ( "PartBufferManager: Buffer space acquired (Available slots after acquire: {0})" , availableAfter ) ;
245236 }
246237
247238 /// <summary>
@@ -267,19 +258,19 @@ public void AddDataSource(IPartDataSource dataSource)
267258 if ( dataSource == null )
268259 throw new ArgumentNullException ( nameof ( dataSource ) ) ;
269260
270- Logger . DebugFormat ( "PartBufferManager: Adding part {0} (BufferedParts count before add: {1})" ,
261+ _logger . DebugFormat ( "PartBufferManager: Adding part {0} (BufferedParts count before add: {1})" ,
271262 dataSource . PartNumber , _partDataSources . Count ) ;
272263
273264 // Add the data source to the collection
274265 if ( ! _partDataSources . TryAdd ( dataSource . PartNumber , dataSource ) )
275266 {
276267 // Duplicate part number - this shouldn't happen in normal operation
277- Logger . Error ( null , "PartBufferManager: Duplicate part {0} attempted to be added" , dataSource . PartNumber ) ;
268+ _logger . Error ( null , "PartBufferManager: Duplicate part {0} attempted to be added" , dataSource . PartNumber ) ;
278269 dataSource ? . Dispose ( ) ; // Clean up the duplicate part
279270 throw new InvalidOperationException ( $ "Duplicate part { dataSource . PartNumber } attempted to be added") ;
280271 }
281272
282- Logger . DebugFormat ( "PartBufferManager: Part {0} added successfully (BufferedParts count after add: {1}). Signaling _partAvailable." ,
273+ _logger . DebugFormat ( "PartBufferManager: Part {0} added successfully (BufferedParts count after add: {1}). Signaling _partAvailable." ,
283274 dataSource . PartNumber , _partDataSources . Count ) ;
284275
285276 // Signal that a new part is available
@@ -370,7 +361,7 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
370361 {
371362 var currentPartNumber = _nextExpectedPartNumber ;
372363
373- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Expecting part {0} (Requested bytes: {1}, BufferedParts count: {2})" ,
364+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Expecting part {0} (Requested bytes: {1}, BufferedParts count: {2})" ,
374365 currentPartNumber , count , _partDataSources . Count ) ;
375366
376367 // Wait for the current part to become available.
@@ -380,7 +371,7 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
380371 // Example: If parts 3, 5, 7 are available but we need part 2, we wait here.
381372 while ( ! _partDataSources . ContainsKey ( currentPartNumber ) )
382373 {
383- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} not yet available. Waiting on _partAvailable event..." ,
374+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} not yet available. Waiting on _partAvailable event..." ,
384375 currentPartNumber ) ;
385376
386377 // Check for completion first to avoid indefinite waiting.
@@ -389,12 +380,12 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
389380 {
390381 if ( state . Item2 != null ) // Check for exception
391382 {
392- Logger . Error ( state . Item2 , "PartBufferManager.ReadFromCurrentPart: Download failed while waiting for part {0}" ,
383+ _logger . Error ( state . Item2 , "PartBufferManager.ReadFromCurrentPart: Download failed while waiting for part {0}" ,
393384 currentPartNumber ) ;
394385 throw new InvalidOperationException ( "Multipart download failed" , state . Item2 ) ;
395386 }
396387
397- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Download complete, part {0} not available. Returning EOF." ,
388+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Download complete, part {0} not available. Returning EOF." ,
398389 currentPartNumber ) ;
399390 // True EOF - all parts downloaded, no more data coming
400391 return ( 0 , false ) ;
@@ -409,19 +400,19 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
409400 // and calls AddDataSourceAsync, it signals this event, waking us to check again.
410401 await Task . Run ( ( ) => _partAvailable . WaitOne ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
411402
412- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Woke from _partAvailable wait. Rechecking for part {0}..." ,
403+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Woke from _partAvailable wait. Rechecking for part {0}..." ,
413404 currentPartNumber ) ;
414405 }
415406
416- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} is available. Reading from data source..." ,
407+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} is available. Reading from data source..." ,
417408 currentPartNumber ) ;
418409
419410 // At this point, the expected part is available in the dictionary.
420411 // Double-check with TryGetValue for safety (handles rare race conditions).
421412 if ( ! _partDataSources . TryGetValue ( currentPartNumber , out var dataSource ) )
422413 {
423414 // Log technical details for troubleshooting
424- Logger . Error ( null , "PartBufferManager: Part {0} disappeared after availability check. This indicates a race condition in the buffer manager." , currentPartNumber ) ;
415+ _logger . Error ( null , "PartBufferManager: Part {0} disappeared after availability check. This indicates a race condition in the buffer manager." , currentPartNumber ) ;
425416
426417 // Throw user-friendly exception
427418 throw new InvalidOperationException ( "Multipart download failed due to an internal error." ) ;
@@ -432,13 +423,13 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
432423 // Read from this part's buffer into the caller's buffer.
433424 var partBytesRead = await dataSource . ReadAsync ( buffer , offset , count , cancellationToken ) . ConfigureAwait ( false ) ;
434425
435- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Read {0} bytes from part {1}. IsComplete={2}" ,
426+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Read {0} bytes from part {1}. IsComplete={2}" ,
436427 partBytesRead , currentPartNumber , dataSource . IsComplete ) ;
437428
438429 // If this part is fully consumed, perform cleanup and advance to next part.
439430 if ( dataSource . IsComplete )
440431 {
441- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} is complete. Cleaning up and advancing to next part..." ,
432+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} is complete. Cleaning up and advancing to next part..." ,
442433 currentPartNumber ) ;
443434
444435 // Remove from collection
@@ -457,7 +448,7 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
457448 // Advance to next part.
458449 _nextExpectedPartNumber ++ ;
459450
460- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Cleaned up part {0}. Next expected part: {1} (BufferedParts count: {2})" ,
451+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Cleaned up part {0}. Next expected part: {1} (BufferedParts count: {2})" ,
461452 currentPartNumber , _nextExpectedPartNumber , _partDataSources . Count ) ;
462453
463454 // Continue reading to fill buffer across part boundaries.
@@ -473,11 +464,11 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
473464 // If part is not complete but we got 0 bytes, it's EOF
474465 if ( partBytesRead == 0 )
475466 {
476- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} returned 0 bytes (EOF)" , currentPartNumber ) ;
467+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} returned 0 bytes (EOF)" , currentPartNumber ) ;
477468 return ( 0 , false ) ;
478469 }
479470
480- Logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} has more data. Returning {1} bytes (will resume on next call)" ,
471+ _logger . DebugFormat ( "PartBufferManager.ReadFromCurrentPart: Part {0} has more data. Returning {1} bytes (will resume on next call)" ,
481472 currentPartNumber , partBytesRead ) ;
482473
483474 // Part still has more data available. Return what we read.
@@ -486,7 +477,7 @@ public async Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancellat
486477 }
487478 catch ( Exception ex )
488479 {
489- Logger . Error ( ex , "PartBufferManager.ReadFromCurrentPart: Error reading from part {0}: {1}" ,
480+ _logger . Error ( ex , "PartBufferManager.ReadFromCurrentPart: Error reading from part {0}: {1}" ,
490481 currentPartNumber , ex . Message ) ;
491482
492483 // Clean up on failure to prevent resource leaks
@@ -518,7 +509,7 @@ public void ReleaseBufferSpace()
518509 _bufferSpaceAvailable . Release ( ) ;
519510
520511 var availableAfter = _bufferSpaceAvailable . CurrentCount ;
521- Logger . DebugFormat ( "PartBufferManager: Buffer space released (Available slots after release: {0})" , availableAfter ) ;
512+ _logger . DebugFormat ( "PartBufferManager: Buffer space released (Available slots after release: {0})" , availableAfter ) ;
522513 }
523514
524515 /// <inheritdoc/>
@@ -543,11 +534,11 @@ public void MarkDownloadComplete(Exception exception)
543534 {
544535 if ( exception != null )
545536 {
546- Logger . Error ( exception , "PartBufferManager: Download marked complete with error. Signaling completion." ) ;
537+ _logger . Error ( exception , "PartBufferManager: Download marked complete with error. Signaling completion." ) ;
547538 }
548539 else
549540 {
550- Logger . DebugFormat ( "PartBufferManager: Download marked complete successfully. Signaling completion." ) ;
541+ _logger . DebugFormat ( "PartBufferManager: Download marked complete successfully. Signaling completion." ) ;
551542 }
552543
553544 // Create and assign new completion state atomically
0 commit comments