它像这样和我一起工作
创建一个 CustomCreationConverter并将其与对象的反序列化一起使用
public class EventInfoConverter : CustomCreationConverter<LogEventInfo>
{
private string _level { get; set; }
public EventInfoConverter(string s)
{
JToken eventinfo = JObject.Parse(s);
var childs = eventinfo.Children();
foreach (var item in childs)
{
if (((Newtonsoft.Json.Linq.JProperty)item).Name == "Level")
{
var m = ((Newtonsoft.Json.Linq.JProperty)item).Value.Children();
foreach (var item1 in m)
{
_level = ((Newtonsoft.Json.Linq.JProperty)item1).Value.ToString();
break;
}
break;
}
}
}
public override LogEventInfo Create(Type objectType)
{
LogEventInfo eventInfo = new LogEventInfo();
switch (_level)
{
case "Info":
eventInfo = new LogEventInfo(LogLevel.Info, "", "");
break;
case "Debug":
eventInfo = new LogEventInfo(LogLevel.Debug, "", "");
break;
case "Error":
eventInfo = new LogEventInfo(LogLevel.Error, "", "");
break;
case "Warn":
eventInfo = new LogEventInfo(LogLevel.Warn, "", "");
break;
default:
break;
}
return eventInfo;
}
}