11using Microsoft . Extensions . Caching . Distributed ;
22using Microsoft . Extensions . Caching . Memory ;
33using Microsoft . Extensions . Logging ;
4+ using Microsoft . Extensions . Logging . Abstractions ;
45using Microsoft . Extensions . Options ;
56using StackExchange . Redis ;
6- using System . Diagnostics . CodeAnalysis ;
77
88namespace L1L2RedisCache ;
99
@@ -35,7 +35,8 @@ public L1L2RedisCache(
3535 L2Cache = l2CacheAccessor ? . Invoke ( ) ??
3636 throw new ArgumentNullException (
3737 nameof ( l2CacheAccessor ) ) ;
38- Logger = logger ;
38+ Logger = logger ??
39+ NullLogger < L1L2RedisCache > . Instance ;
3940 MessagePublisher = messagePublisher ??
4041 throw new ArgumentNullException (
4142 nameof ( messagePublisher ) ) ;
@@ -87,7 +88,7 @@ public L1L2RedisCache(
8788 /// <summary>
8889 /// Optional. The logger.
8990 /// </summary>
90- public ILogger < L1L2RedisCache > ? Logger { get ; }
91+ public ILogger < L1L2RedisCache > Logger { get ; }
9192
9293 /// <summary>
9394 /// The pub/sub publisher.
@@ -121,7 +122,6 @@ public void Dispose()
121122 /// </summary>
122123 /// <param name="key">A string identifying the requested value.</param>
123124 /// <returns>The located value or null.</returns>
124- [ SuppressMessage ( "Reliability" , "CA2000" ) ]
125125 public byte [ ] ? Get ( string key )
126126 {
127127 var value = L1Cache . Get (
@@ -245,7 +245,6 @@ await L2Cache
245245 /// Removes the value with the given key.
246246 /// </summary>
247247 /// <param name="key">A string identifying the requested value.</param>
248- [ SuppressMessage ( "Reliability" , "CA2000" ) ]
249248 public void Remove ( string key )
250249 {
251250 var semaphore = GetOrCreateLock ( key , null ) ;
@@ -313,7 +312,6 @@ await MessagePublisher
313312 /// <param name="key">A string identifying the requested value.</param>
314313 /// <param name="value">The value to set in the cache.</param>
315314 /// <param name="options">The cache options for the value.</param>
316- [ SuppressMessage ( "Reliability" , "CA2000" ) ]
317315 public void Set (
318316 string key ,
319317 byte [ ] value ,
@@ -456,7 +454,6 @@ private SemaphoreSlim GetOrCreateLock(
456454 }
457455 }
458456
459- [ SuppressMessage ( "Reliability" , "CA2000" ) ]
460457 private async Task < SemaphoreSlim > GetOrCreateLockAsync (
461458 string key ,
462459 DistributedCacheEntryOptions ? distributedCacheEntryOptions ,
@@ -547,7 +544,7 @@ private async Task SubscribeAsync(
547544 cancellationToken )
548545 . ConfigureAwait ( false ) )
549546 {
550- Logger ? . MessagingConfigurationInvalid (
547+ Logger . MessagingConfigurationInvalid (
551548 L1L2RedisCacheOptions . MessagingType ) ;
552549 }
553550
@@ -560,7 +557,7 @@ await MessageSubscriber
560557 }
561558 catch ( RedisConnectionException redisConnectionException )
562559 {
563- Logger ? . SubscriberFailed (
560+ Logger . SubscriberFailed (
564561 L1L2RedisCacheOptions
565562 . SubscriberRetryDelay ,
566563 redisConnectionException ) ;
0 commit comments