Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/AutomationUtils/Matchers/ExceptionEventMatcher.cs
Ben Marsh 878f74458e Horde: Use long-lived regex instances for matching patterns.
#preflight 62963a2b95336ad2bfbfe846

[CL 20438090 by Ben Marsh in ue5-main branch]
2022-05-31 12:02:25 -04:00

35 lines
842 B
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Core;
using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
#nullable enable
namespace AutomationUtils.Matchers
{
/// <summary>
/// Matches a generic C# exception
/// </summary>
class ExceptionEventMatcher : ILogEventMatcher
{
static readonly Regex s_pattern = new Regex(@"^\s*Unhandled Exception: ");
static readonly Regex s_atPattern = new Regex(@"^\s*at ");
/// <inheritdoc/>
public LogEventMatch? Match(ILogCursor cursor)
{
if (cursor.IsMatch(s_pattern))
{
LogEventBuilder builder = new LogEventBuilder(cursor);
while(builder.Current.IsMatch(1, s_atPattern))
{
builder.MoveNext();
}
return builder.ToMatch(LogEventPriority.Low, LogLevel.Error, KnownLogEvents.Exception);
}
return null;
}
}
}