Files
ersatztv/ErsatzTV.Application/Logs/Mapper.cs
Jason Dove 245c4ec359 code analysis and cleanup (#1411)
* cleanup scanner project

* cleanup infrastructure projects

* cleanup ffmpeg project

* cleanup core project

* cleanup app project

* cleanup main project

* update dependencies

* code cleanup
2023-09-03 06:23:42 -05:00

31 lines
922 B
C#

using System.Text.RegularExpressions;
using Serilog.Events;
namespace ErsatzTV.Application.Logs;
internal sealed partial class Mapper
{
[GeneratedRegex(@"(.*)\[(DBG|INF|WRN|ERR|FTL)\](.*)")]
private static partial Regex LogEntryRegex();
internal static Option<LogEntryViewModel> ProjectToViewModel(string line)
{
Match match = LogEntryRegex().Match(line);
if (!match.Success || !DateTimeOffset.TryParse(match.Groups[1].Value, out DateTimeOffset timestamp))
{
return None;
}
LogEventLevel level = match.Groups[2].Value switch
{
"FTL" => LogEventLevel.Fatal,
"ERR" => LogEventLevel.Error,
"WRN" => LogEventLevel.Warning,
"INF" => LogEventLevel.Information,
_ => LogEventLevel.Debug
};
return new LogEntryViewModel(timestamp, level, match.Groups[3].Value);
}
}