1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Debug - Fixed threading issue with LogStore

also made the logger viewer text searching much more efficient
This commit is contained in:
Diogo Trindade 2023-03-01 17:35:35 +00:00
parent a7ed4de575
commit 1b62109961
2 changed files with 22 additions and 5 deletions

View File

@ -10,12 +10,25 @@ namespace Artemis.Core;
/// </summary> /// </summary>
public static class LogStore public static class LogStore
{ {
private static readonly object _lock = new();
private static readonly LinkedList<LogEvent> LinkedList = new(); private static readonly LinkedList<LogEvent> LinkedList = new();
/// <summary> /// <summary>
/// Gets a list containing the last 500 log events. /// Gets a list containing the last 500 log events.
/// </summary> /// </summary>
public static List<LogEvent> Events => LinkedList.ToList(); public static List<LogEvent> Events
{
get
{
List<LogEvent> events;
lock (_lock)
events = LinkedList.ToList();
return events;
}
}
/// <summary> /// <summary>
/// Occurs when a new <see cref="LogEvent" /> was received. /// Occurs when a new <see cref="LogEvent" /> was received.
@ -24,9 +37,13 @@ public static class LogStore
internal static void Emit(LogEvent logEvent) internal static void Emit(LogEvent logEvent)
{ {
LinkedList.AddLast(logEvent); lock (_lock)
while (LinkedList.Count > 500) {
LinkedList.RemoveFirst(); LinkedList.AddLast(logEvent);
while (LinkedList.Count > 500)
LinkedList.RemoveFirst();
}
OnEventAdded(new LogEventEventArgs(logEvent)); OnEventAdded(new LogEventEventArgs(logEvent));
} }

View File

@ -63,7 +63,7 @@ public class LogsDebugViewModel : ActivatableViewModelBase
private void RemoveOldestLine() private void RemoveOldestLine()
{ {
int firstNewLine = Document.Text.IndexOf('\n'); int firstNewLine = Document.IndexOf('\n', 0, Document.TextLength);
if (firstNewLine == -1) if (firstNewLine == -1)
{ {
//this should never happen. //this should never happen.