mirror of https://github.com/ErsatzTV/ErsatzTV.git
3 changed files with 49 additions and 14 deletions
@ -1,12 +1,12 @@
@@ -1,12 +1,12 @@
|
||||
using System; |
||||
using Serilog.Events; |
||||
|
||||
namespace ErsatzTV.Application.Logs |
||||
{ |
||||
public record LogEntryViewModel( |
||||
int Id, |
||||
DateTime Timestamp, |
||||
string Level, |
||||
LogEventLevel Level, |
||||
string Exception, |
||||
string RenderedMessage, |
||||
string Properties); |
||||
string Message); |
||||
} |
||||
|
@ -1,16 +1,45 @@
@@ -1,16 +1,45 @@
|
||||
using ErsatzTV.Core.Domain; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ErsatzTV.Core.Domain; |
||||
using Newtonsoft.Json.Linq; |
||||
using Serilog.Events; |
||||
|
||||
namespace ErsatzTV.Application.Logs |
||||
{ |
||||
internal static class Mapper |
||||
{ |
||||
internal static LogEntryViewModel ProjectToViewModel(LogEntry logEntry) => |
||||
new( |
||||
internal static LogEntryViewModel ProjectToViewModel(LogEntry logEntry) |
||||
{ |
||||
string message = logEntry.RenderedMessage; |
||||
if (!string.IsNullOrWhiteSpace(logEntry.Properties)) |
||||
{ |
||||
foreach (KeyValuePair<string, JToken> property in JObject.Parse(logEntry.Properties)) |
||||
{ |
||||
var token = $"{{{property.Key}}}"; |
||||
if (message.Contains(token)) |
||||
{ |
||||
message = message.Replace(token, property.Value.ToString()); |
||||
} |
||||
|
||||
var destructureToken = $"{{@{property.Key}}}"; |
||||
if (message.Contains(destructureToken)) |
||||
{ |
||||
message = message.Replace(destructureToken, property.Value.ToString()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (!Enum.TryParse(logEntry.Level, out LogEventLevel level)) |
||||
{ |
||||
level = LogEventLevel.Debug; |
||||
} |
||||
|
||||
return new LogEntryViewModel( |
||||
logEntry.Id, |
||||
logEntry.Timestamp, |
||||
logEntry.Level, |
||||
level, |
||||
logEntry.Exception, |
||||
logEntry.RenderedMessage, |
||||
logEntry.Properties); |
||||
message); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue