从 ILogEventPropertyFactory 获取原始 属性 值类型

Get original property value type from ILogEventPropertyFactory

我正在编写最简单的增强器:找到所有具有枚举值类型的属性 XProperty 并添加另一个名为 XPropertyString 的 属性,这是枚举值的字符串表示形式.

我是这样开始的:

    public class EnumStringEnricher : ILogEventEnricher
    {
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            foreach(var p in logEvent.Properties)
            {
                Type t = p.Value?.GetType();
                if (t != null && t.IsEnum)
                {
                    //create property <enum_property>String with Enum description as value
                    LogEventProperty enumString = propertyFactory.CreateProperty($"{p.Key}String", Enum.GetName(t, p.Value));
                    logEvent.AddPropertyIfAbsent(enumString);
                }
            }
        }
    }

似乎 属性 值是“包装”的 Serilog 类型 Serilog.Events.ScalarValueSerilog.Events.SequenceValue

在上面的例子中有什么方法可以得到底层的 属性 值类型吗?

        foreach(var p in logEvent.Properties)
        {
            if (p.Value is ScalarValue sv)
            {
                Type t = sv.Value?.GetType();