diff --git a/src/Artemis.Core/Stores/LogStore.cs b/src/Artemis.Core/Stores/LogStore.cs index de459357d..a4a3e66ed 100644 --- a/src/Artemis.Core/Stores/LogStore.cs +++ b/src/Artemis.Core/Stores/LogStore.cs @@ -10,12 +10,25 @@ namespace Artemis.Core; /// public static class LogStore { + private static readonly object _lock = new(); + private static readonly LinkedList LinkedList = new(); /// /// Gets a list containing the last 500 log events. /// - public static List Events => LinkedList.ToList(); + public static List Events + { + get + { + List events; + + lock (_lock) + events = LinkedList.ToList(); + + return events; + } + } /// /// Occurs when a new was received. @@ -24,9 +37,13 @@ public static class LogStore internal static void Emit(LogEvent logEvent) { - LinkedList.AddLast(logEvent); - while (LinkedList.Count > 500) - LinkedList.RemoveFirst(); + lock (_lock) + { + LinkedList.AddLast(logEvent); + while (LinkedList.Count > 500) + LinkedList.RemoveFirst(); + } + OnEventAdded(new LogEventEventArgs(logEvent)); } diff --git a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs index 37d85d39d..c1860b01a 100644 --- a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs +++ b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs @@ -63,7 +63,7 @@ public class LogsDebugViewModel : ActivatableViewModelBase private void RemoveOldestLine() { - int firstNewLine = Document.Text.IndexOf('\n'); + int firstNewLine = Document.IndexOf('\n', 0, Document.TextLength); if (firstNewLine == -1) { //this should never happen.