Chad Jessup
Chad Jessup

Reputation: 620

How to deserialize LogEvents from Serilog stored in CouchDB

I'm currently logging (Logging application) to a CouchDB database with Serilog, and with a handful of Types being decomposed into the database.

I've got a separate application (Reporting application) that is trying to pull LogEvents out of the database and deserialize them into the original LogEvents. The Reporting application is just as aware of the same types as the logging application and the specific Types in the database are fully decomposed into it.

Json.Net's deserializer has problems with deserializing the MessageTemplate. Even with a custom converter, it has so many problems that I'm probably doing it wrong (various exceptions deserializing, but no real pattern that I can tell).

Has anyone been able to do this successfully? I was under the impression that being able to pull Types out of the logs is one of the features of Serilog, and all the data is there, so I don't see why it's not possible.

These Types are all fully serializable as well, they're regularly serialized/deserialized by Json.net.

Upvotes: 3

Views: 1270

Answers (1)

Chad Jessup
Chad Jessup

Reputation: 620

After more research, I've found a way to partially solve the problem. Generate new classes with http://json2csharp.com/ - rename the RootObject to something (e.g., SpecificLogEvent) and use:

var logEvent = JsonConvert.DeserializeObject<SpecificLogEvent>(doc.Value);

Then convert the objects to the real objects where needed. I'll not mark this as the answer for awhile, because I'd love an easy back and forth and avoid this extra step which creates redundant classes.

Upvotes: 1

Related Questions