diff options
Diffstat (limited to 'src/SMAPI/Framework/Monitor.cs')
-rw-r--r-- | src/SMAPI/Framework/Monitor.cs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs index 06cf1b46..f630c7fe 100644 --- a/src/SMAPI/Framework/Monitor.cs +++ b/src/SMAPI/Framework/Monitor.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using StardewModdingAPI.Framework.Logging; using StardewModdingAPI.Internal.ConsoleWriting; @@ -26,6 +27,9 @@ namespace StardewModdingAPI.Framework /// <summary>The maximum length of the <see cref="LogLevel"/> values.</summary> private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>() select level.ToString().Length).Max(); + /// <summary>A cache of messages that should only be logged once.</summary> + private readonly HashSet<string> LogOnceCache = new HashSet<string>(); + /********* ** Accessors @@ -74,6 +78,15 @@ namespace StardewModdingAPI.Framework this.LogImpl(this.Source, message, (ConsoleLogLevel)level); } + /// <summary>Log a message for the player or developer, but only if it hasn't already been logged since the last game launch.</summary> + /// <param name="message">The message to log.</param> + /// <param name="level">The log severity level.</param> + public void LogOnce(string message, LogLevel level = LogLevel.Trace) + { + if (this.LogOnceCache.Add($"{message}|{level}")) + this.LogImpl(this.Source, message, (ConsoleLogLevel)level); + } + /// <summary>Log a message that only appears when <see cref="IMonitor.IsVerbose"/> is enabled.</summary> /// <param name="message">The message to log.</param> public void VerboseLog(string message) |