Add Elastic-bound logging of (almost) all database update events

This commit is contained in:
Ske
2020-08-27 21:28:36 +02:00
parent 8d27148bdf
commit 9955dc29f9
11 changed files with 182 additions and 45 deletions

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Serilog.Core;
using Serilog.Events;
namespace PluralKit.Core
{
public class PatchObjectDestructuring: IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory factory,
out LogEventPropertyValue result)
{
result = null;
if (!(value is PatchObject po)) return false;
var propList = new List<LogEventProperty>();
foreach (var props in po.GetType().GetProperties())
{
var propValue = props.GetValue(po);
if (propValue is IPartial p && p.IsPresent)
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(p.RawValue)));
else if (!(propValue is IPartial))
propList.Add(new LogEventProperty(props.Name, factory.CreatePropertyValue(propValue)));
}
result = new StructureValue(propList);
return true;
}
}
}