여기에 제안 된 방법을 사용하여 JSON.NET JSson 문자열을 BsonDocument로 변환하는 데 문제가 있습니다. Convert string into MongoDB BsonDocument. LogMessages를 mongodb를 다시 삽입하는 MongoDbLog4net appender를 작성하고 있습니다. 이러한 메시지에는 예외가 포함될 수 있으며 경우에 따라 예외 객체가 점 '을 포함하는 json 문자열로 직렬화됩니다.' 일부 키에서 BsonSerializer.Desrialize 메서드가 불평을 일으켰습니다. JsonConvert에게 무효 한 문자를 다른 것으로 바꾸거나 바꾸지 말라고 말하는 쉽고 효율적인 방법이 있습니까?문자열을 MongoDB로 변환 BsonDocument (속편)
protected override void Append(LoggingEvent loggingEvent)
{
// the log message here is used to filter and collect the
// fields from loggingEvent we are interested in
var logMessage = new LogMessage(loggingEvent);
// since mongodb does not serialize exceptions very well we
// will use JSON.NET to serialize the LogMessage instance
// and build the BSON document from it
string jsonLogMessage = JsonConvert.SerializeObject(logMessage);
var bsonLogMessage = BsonSerializer.Deserialize<BsonDocument>(jsonLogMessage);
this.logCollection.Insert(bsonLogMessage);
}
디시리얼라이저가 유효한 json 문서에서 오류가 발생하는 경우 재현 할 수 있도록 jer.mongodb.org에서 간단한 예제로 버그 보고서를 제출하십시오. –
Deserializer의 버그가 아닙니다. { "Key.with.points": "Value"} 같은 것을 BsonDocument로 변환하는 것을 허용하지 않습니다. 나는 그 어딘가를 읽었다. ' 및 '$'는 BsonDocument의 키에서 허용되지 않습니다. –