Improve logging performance by checking Trace/Debug log level is enabled (#12793)
This commit is contained in:
@@ -66,8 +66,10 @@ public class SqliteDistributedLockingMechanism : IDistributedLockingMechanism
|
||||
_timeout = timeout;
|
||||
LockId = lockId;
|
||||
LockType = lockType;
|
||||
|
||||
_parent._logger.LogDebug("Requesting {lockType} for id {id}", LockType, LockId);
|
||||
if (_parent._logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
|
||||
{
|
||||
_parent._logger.LogDebug("Requesting {lockType} for id {id}", LockType, LockId);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -92,17 +94,24 @@ public class SqliteDistributedLockingMechanism : IDistributedLockingMechanism
|
||||
|
||||
throw new DistributedWriteLockTimeoutException(LockId);
|
||||
}
|
||||
|
||||
_parent._logger.LogDebug("Acquired {lockType} for id {id}", LockType, LockId);
|
||||
if (_parent._logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
|
||||
{
|
||||
_parent._logger.LogDebug("Acquired {lockType} for id {id}", LockType, LockId);
|
||||
}
|
||||
}
|
||||
|
||||
public int LockId { get; }
|
||||
|
||||
public DistributedLockType LockType { get; }
|
||||
|
||||
public void Dispose() =>
|
||||
// Mostly no op, cleaned up by completing transaction in scope.
|
||||
_parent._logger.LogDebug("Dropped {lockType} for id {id}", LockType, LockId);
|
||||
public void Dispose()
|
||||
{
|
||||
if (_parent._logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
|
||||
{
|
||||
// Mostly no op, cleaned up by completing transaction in scope.
|
||||
_parent._logger.LogDebug("Dropped {lockType} for id {id}", LockType, LockId);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> $"SqliteDistributedLock({LockId})";
|
||||
|
||||
Reference in New Issue
Block a user