Creates a from a dictionary as deserialized from JSON. The from which to create the . A with the values in the dictionary.
(Dictionary<string, object?> entryDictionary)
| 67 | /// which to create the <see cref="LogEntry"/>.</param> |
| 68 | /// <returns>A <see cref="LogEntry"/> with the values in the dictionary.</returns> |
| 69 | internal static LogEntry FromDictionary(Dictionary<string, object?> entryDictionary) |
| 70 | { |
| 71 | LogEntry entry = new LogEntry(); |
| 72 | if (entryDictionary.TryGetValue("message", out object? message)) |
| 73 | { |
| 74 | entry.Message = message?.ToString() ?? string.Empty; |
| 75 | } |
| 76 | |
| 77 | if (entryDictionary.TryGetValue("timestamp", out object? timestamp)) |
| 78 | { |
| 79 | double timestampValue = Convert.ToDouble(timestamp, CultureInfo.InvariantCulture); |
| 80 | entry.Timestamp = UnixEpoch.AddMilliseconds(timestampValue); |
| 81 | } |
| 82 | |
| 83 | if (entryDictionary.TryGetValue("level", out object? level)) |
| 84 | { |
| 85 | if (Enum.TryParse(level?.ToString(), ignoreCase: true, out LogLevel result)) |
| 86 | { |
| 87 | entry.Level = result; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | // If the requested log level string is not a valid log level, |
| 92 | // ignore it and use LogLevel.All. |
| 93 | entry.Level = LogLevel.All; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return entry; |
| 98 | } |
| 99 | } |
nothing calls this directly
no test coverage detected