@@ -11,16 +11,18 @@ namespace CoreHelpers.TaskLogging
1111{
1212 internal class AzureStorageTableTaskLoggerFactory : ITaskLoggerFactory
1313 {
14- private int _cacheLimit ;
15- private string _environmentPrefix ;
16- private TableServiceClient _tableServiceClient ;
14+ private readonly int _cacheLimit ;
15+ private readonly TimeSpan _cacheTimespan ;
16+ private readonly string _environmentPrefix ;
17+ private readonly TableServiceClient _tableServiceClient ;
1718 private long _messageTimeStampCounter = 0 ;
1819
19- public AzureStorageTableTaskLoggerFactory ( string connectionString , string environmentPrefix , int cacheLimit )
20+ public AzureStorageTableTaskLoggerFactory ( string connectionString , string environmentPrefix , int cacheLimit , TimeSpan cacheTimespan )
2021 {
2122 _tableServiceClient = new TableServiceClient ( connectionString ) ;
2223 _environmentPrefix = environmentPrefix ;
23- _cacheLimit = cacheLimit ;
24+ _cacheLimit = cacheLimit ;
25+ _cacheTimespan = cacheTimespan ;
2426 }
2527
2628 public async Task < string > AnnounceTask ( string taskType , string taskSource , string taskWorker )
@@ -99,7 +101,7 @@ public async Task UpdateTaskStatus(string taskKey, TaskStatus taskStatus)
99101
100102 public ITaskLogger CreateTaskLogger ( string taskKey )
101103 {
102- return new AzureStorageTableTaskLogger ( taskKey , _cacheLimit , this ) ;
104+ return new AzureStorageTableTaskLogger ( taskKey , _cacheLimit , _cacheTimespan , this ) ;
103105 }
104106
105107 public async Task Flush ( DateTimeOffset flushTime , string taskKey , IEnumerable < string > messages )
@@ -207,7 +209,13 @@ public static class AzureStorageTableTaskLoggerFactoryServiceCollectionExtension
207209 {
208210 public static IServiceCollection AddTaskLoggerForAzureStorageTable ( this IServiceCollection services , string connectionString , string environmentPrefix , int lineCacheLimit )
209211 {
210- services . AddSingleton < ITaskLoggerFactory > ( new AzureStorageTableTaskLoggerFactory ( connectionString , environmentPrefix , lineCacheLimit ) ) ;
212+ services . AddSingleton < ITaskLoggerFactory > ( new AzureStorageTableTaskLoggerFactory ( connectionString , environmentPrefix , lineCacheLimit , TimeSpan . FromMinutes ( 5 ) ) ) ;
213+ return services ;
214+ }
215+
216+ public static IServiceCollection AddTaskLoggerForAzureStorageTable ( this IServiceCollection services , string connectionString , string environmentPrefix , int lineCacheLimit , TimeSpan cacheTimeSpan )
217+ {
218+ services . AddSingleton < ITaskLoggerFactory > ( new AzureStorageTableTaskLoggerFactory ( connectionString , environmentPrefix , lineCacheLimit , cacheTimeSpan ) ) ;
211219 return services ;
212220 }
213221 }
0 commit comments