Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion SysManager/SysManager/Services/EventLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Author: laurentiu021 · https://github.com/laurentiu021/SystemManager
// License: MIT

using System.Buffers;
using System.Diagnostics.Eventing.Reader;
using SysManager.Models;

Expand Down Expand Up @@ -113,10 +114,14 @@ private static string SafeFormatMessage(EventRecord rec)
catch (InvalidOperationException) { return "(message not available)"; }
}

// Hoisted so the newline scan in FirstLine — run once per projected event
// record, potentially thousands per query — doesn't allocate a char[] per call.
private static readonly SearchValues<char> Newlines = SearchValues.Create("\r\n");

private static string FirstLine(string s)
{
if (string.IsNullOrEmpty(s)) return "";
var i = s.IndexOfAny(new[] { '\r', '\n' });
var i = s.AsSpan().IndexOfAny(Newlines);
return (i < 0 ? s : s[..i]).Trim();
}

Expand Down
10 changes: 7 additions & 3 deletions SysManager/SysManager/Services/LogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SysManager.Services;

public static class LogService
public static partial class LogService
{
public static Logger? Logger { get; private set; }

Expand All @@ -33,10 +33,14 @@ private static Regex BuildUserPathRegex()
return new Regex($@"(?i)({escaped})[^\\]+", RegexOptions.Compiled);
}
}
// Fallback: match any drive letter followed by \Users\<username>
return new Regex(@"(?i)([A-Z]:\\Users\\)[^\\]+", RegexOptions.Compiled);
// Fallback: match any drive letter followed by \Users\<username>.
// This branch is a constant pattern, so it is source-generated.
return FallbackUserPathRegex();
}

[GeneratedRegex(@"(?i)([A-Z]:\\Users\\)[^\\]+")]
private static partial Regex FallbackUserPathRegex();

public static void Init()
{
Directory.CreateDirectory(LogDir);
Expand Down
Loading