diff --git a/src/AsyncLogSinkBase.cs b/src/AsyncLogSinkBase.cs index a2611a5..2a859c8 100644 --- a/src/AsyncLogSinkBase.cs +++ b/src/AsyncLogSinkBase.cs @@ -19,6 +19,7 @@ public abstract class AsyncLogSinkBase(IAsyncLogMessageWriter logMessageWriters = new(); + private int isDisabled; // ┌─────────────────────────────────────────────────────────────────────────────┐ diff --git a/src/LogSinkBase.cs b/src/LogSinkBase.cs index 5c647d6..61ee3fa 100644 --- a/src/LogSinkBase.cs +++ b/src/LogSinkBase.cs @@ -122,6 +122,23 @@ public IDisposable RegisterLogMessageWriter(ILogMessageWriter logMessageWriters.TryRemove(typeof(TPayload), out _)); } + /// + /// Disables this log sink, preventing it from processing any log messages until it is re-enabled. + /// + /// A that, when disposed, re-enables the log sink. + /// Thrown if the log sink is already disabled. + public IDisposable Disable() + { + if (IsDisabled) + { + throw new InvalidOperationException("The log sink is already disabled."); + } + + IsDisabled = true; + + return new DelegateDisposable(() => IsDisabled = false); + } + // ┌─────────────────────────────────────────────────────────────────────────────┐ // │ Private Methods │ // └─────────────────────────────────────────────────────────────────────────────┘