44using System . Threading . Tasks ;
55using ByteSync . Common . Helpers ;
66using ByteSync . Common . Interfaces ;
7- using Serilog ;
7+ using Microsoft . Extensions . Logging ;
88
99// ReSharper disable UnusedType.Global
1010// ReSharper disable UnusedMember.Global
@@ -13,8 +13,12 @@ namespace ByteSync.Common.Controls;
1313
1414public abstract class BaseRepository < T > : IRepository < T >
1515{
16- protected BaseRepository ( )
16+ protected readonly ILogger < BaseRepository < T > > _logger ;
17+
18+ protected BaseRepository ( ILogger < BaseRepository < T > > logger )
1719 {
20+ _logger = logger ;
21+
1822 SyncRoot = new object ( ) ;
1923
2024 IsDataSetEvent = new ManualResetEvent ( false ) ;
@@ -63,7 +67,7 @@ await Task.Run(() =>
6367 Data = ( T ) Activator . CreateInstance ( typeof ( T ) , newDataId ) ;
6468 IsDataSetEvent . Set ( ) ;
6569
66- Log . Debug ( "{HolderType}.ResetDataAsync, DataId:{DataId}" , GetType ( ) . Name , GetDataId ( Data ) ) ;
70+ _logger . LogDebug ( "{HolderType}.ResetDataAsync, DataId:{DataId}" , GetType ( ) . Name , GetDataId ( Data ) ) ;
6771
6872 if ( func != null )
6973 {
@@ -203,19 +207,19 @@ public bool Wait(string dataId, Func<T, EventWaitHandle> func, Func<T, TimeSpan?
203207 {
204208 return true ;
205209 }
206- if ( waitHandles [ index ] == endEvent )
210+ if ( index < waitHandles . Count && waitHandles [ index ] == endEvent )
207211 {
208- Log . Error ( "Wait: Process has ended" ) ;
212+ _logger . LogError ( "Wait: Process has ended" ) ;
209213 return false ;
210214 }
211- if ( waitHandles [ index ] == cancellationToken . WaitHandle )
215+ if ( index < waitHandles . Count && waitHandles [ index ] == cancellationToken . WaitHandle )
212216 {
213217 if ( cancellationToken . IsCancellationRequested )
214218 {
215219 return true ;
216220 }
217221 }
218- Log . Error ( "Wait: timeout has occured" ) ;
222+ _logger . LogError ( "Wait: timeout has occured" ) ;
219223 return false ;
220224 }
221225
@@ -239,7 +243,7 @@ private T2 CheckAndRun<T2>(string? dataId, Func<T, T2> func)
239243 {
240244 if ( dataId != null && ! CheckDataId ( dataId , Data ) )
241245 {
242- Log . Debug ( "dataId is not expected. Current DataId:{CurrentDataId}, Incoming dataId:{IncomingDataId}" , GetDataId ( Data ) , dataId ) ;
246+ _logger . LogDebug ( "dataId is not expected. Current DataId:{CurrentDataId}, Incoming dataId:{IncomingDataId}" , GetDataId ( Data ) , dataId ) ;
243247 throw new ArgumentOutOfRangeException ( nameof ( dataId ) , "dataId is not expected" ) ;
244248 }
245249
0 commit comments