diff --git a/Directory.Packages.props b/Directory.Packages.props
index 0c18175..b0c762e 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -27,6 +27,8 @@
+
+
diff --git a/src/AsyncLogSinkBase.cs b/src/AsyncLogSinkBase.cs
index c56fb1c..a2611a5 100644
--- a/src/AsyncLogSinkBase.cs
+++ b/src/AsyncLogSinkBase.cs
@@ -63,7 +63,7 @@ public TWriter Writer
}
}
} = writer;
-
+
///
/// Gets or sets a value indicating whether this sink is disabled.
///
@@ -73,7 +73,7 @@ public TWriter Writer
public bool IsDisabled
{
get => Volatile.Read(ref isDisabled) == 1;
- set => Interlocked.Exchange(ref isDisabled, value ? 1 : 0);
+ private set => Interlocked.Exchange(ref isDisabled, value ? 1 : 0);
}
// ┌─────────────────────────────────────────────────────────────────────────────┐
@@ -122,6 +122,23 @@ public IDisposable RegisterLogMessageWriter(IAsyncLogMessageWriter 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 │
// └─────────────────────────────────────────────────────────────────────────────┘
diff --git a/src/LogMessageWriter/IHasWriter.cs b/src/LogMessageWriter/IHasWriter.cs
index f579912..15d52d7 100644
--- a/src/LogMessageWriter/IHasWriter.cs
+++ b/src/LogMessageWriter/IHasWriter.cs
@@ -13,5 +13,5 @@ public interface IHasWriter
///
/// Gets or sets the .
///
- public TWriter Writer { get; set;}
+ public TWriter Writer { get; set; }
}
\ No newline at end of file
diff --git a/tests/AsyncLogSinkBaseTests/src/MethodTests/DisableMethodTests.cs b/tests/AsyncLogSinkBaseTests/src/MethodTests/DisableMethodTests.cs
new file mode 100644
index 0000000..0452d0c
--- /dev/null
+++ b/tests/AsyncLogSinkBaseTests/src/MethodTests/DisableMethodTests.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AwesomeAssertions;
+using FakeItEasy;
+using WB.Logging;
+using WB.Logging.LogSinks.Base;
+
+namespace AsyncLogSinkBaseTests.MethodTests.DisableMethodTests;
+
+internal sealed class TestWriter
+{
+}
+
+internal sealed class TestLogSink() : AsyncLogSinkBase(new TestLogMessageWriter(), new TestWriter())
+{
+}
+
+internal sealed class TestLogMessageWriter : IAsyncLogMessageWriter