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:
parent
a7ed4de575
commit
1b62109961
@ -10,12 +10,25 @@ namespace Artemis.Core;
|
||||
/// </summary>
|
||||
public static class LogStore
|
||||
{
|
||||
private static readonly object _lock = new();
|
||||
|
||||
private static readonly LinkedList<LogEvent> LinkedList = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing the last 500 log events.
|
||||
/// </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>
|
||||
/// Occurs when a new <see cref="LogEvent" /> was received.
|
||||
@ -23,10 +36,14 @@ public static class LogStore
|
||||
public static event EventHandler<LogEventEventArgs>? EventAdded;
|
||||
|
||||
internal static void Emit(LogEvent logEvent)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
LinkedList.AddLast(logEvent);
|
||||
while (LinkedList.Count > 500)
|
||||
LinkedList.RemoveFirst();
|
||||
}
|
||||
|
||||
|
||||
OnEventAdded(new LogEventEventArgs(logEvent));
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user