summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-08-24 19:25:57 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-08-24 19:25:57 -0400
commit046deb2d56b6d4665280cc5478d9e683ec1d777d (patch)
treebccc347514ecfe1801994232c0c40ba43782adb9 /src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs
parent46d63e11cc76c70ff77ee90edb6cc055c63e7224 (diff)
downloadSMAPI-046deb2d56b6d4665280cc5478d9e683ec1d777d.tar.gz
SMAPI-046deb2d56b6d4665280cc5478d9e683ec1d777d.tar.bz2
SMAPI-046deb2d56b6d4665280cc5478d9e683ec1d777d.zip
simplify console interception flow
The console interceptor now uses a marker in the string (instead of a state field) to track whether the message should intercepted. This makes each write more atomic, so it's less affected by multithreading in some cases.
Diffstat (limited to 'src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs')
-rw-r--r--src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs b/src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs
deleted file mode 100644
index ef42e536..00000000
--- a/src/SMAPI/Framework/Logging/ConsoleInterceptionManager.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using System;
-
-namespace StardewModdingAPI.Framework.Logging
-{
- /// <summary>Manages console output interception.</summary>
- internal class ConsoleInterceptionManager : IDisposable
- {
- /*********
- ** Fields
- *********/
- /// <summary>The intercepting console writer.</summary>
- private readonly InterceptingTextWriter Output;
-
-
- /*********
- ** Accessors
- *********/
- /// <summary>The event raised when a message is written to the console directly.</summary>
- public event Action<string> OnMessageIntercepted;
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Construct an instance.</summary>
- public ConsoleInterceptionManager()
- {
- // redirect output through interceptor
- this.Output = new InterceptingTextWriter(Console.Out);
- this.Output.OnMessageIntercepted += line => this.OnMessageIntercepted?.Invoke(line);
- Console.SetOut(this.Output);
- }
-
- /// <summary>Get an exclusive lock and write to the console output without interception.</summary>
- /// <param name="action">The action to perform within the exclusive write block.</param>
- public void ExclusiveWriteWithoutInterception(Action action)
- {
- lock (Console.Out)
- {
- try
- {
- this.Output.ShouldIntercept = false;
- action();
- }
- finally
- {
- this.Output.ShouldIntercept = true;
- }
- }
- }
-
- /// <summary>Release all resources.</summary>
- public void Dispose()
- {
- Console.SetOut(this.Output.Out);
- this.Output.Dispose();
- }
- }
-}