mongodb - Element 'timestamp' does not match any field or property of class (Log4Mongo deserialization) -
i building web app , use log4mongo store app logs "logs" collection in mongo database.
here mongodbappender in web.config
<appender name="mongodbappender" type="log4mongo.mongodbappender, log4mongo"> <connectionstring value="mongodb://localhost/insurancegrader?safe=true" /> <collectionname value="logs" /> <field> <name value="timestamp" /> <layout type="log4net.layout.rawtimestamplayout" /> </field> <field> <name value="level" /> <layout type="log4net.layout.patternlayout" value="%level" /> </field> <field> <name value="thread" /> <layout type="log4net.layout.patternlayout" value="%thread" /> </field> <field> <name value="logger" /> <layout type="log4net.layout.patternlayout" value="%logger" /> </field> <field> <name value="message" /> <layout type="log4net.layout.patternlayout" value="%message" /> </field> <field> <name value="mycustomproperty" /> <layout type="log4net.layout.rawpropertylayout"> <key value="mycustomproperty" /> </layout> </field> </appender>
json format this
{ "_id" : objectid("51921692a777da8788faa22c"), "timestamp" : isodate("2013-05-14t10:48:50.018z"), "level" : "error", "thread" : "100", "logger" : "type of class", "message" : "some info here" }
i build class store object after deserialization
public class logentry { public objectid id { get; set; } [bsondatetimeoptions(kind = datetimekind.local)] [jsonproperty("timestamp")] public datetime timestamp { get; set; } [jsonproperty("level")] public string level { get; set; } [jsonproperty("logger")] public string logger { get; set; } [jsonproperty("message")] public string message { get; set; } }
however, error when deserialize logs json logentry object not sure why. or advice appreciated!
element 'timestamp' not match field or property of class
the simple resolution correct properties of logentry class same in json format (remove jsonproperty(...), leading convention code issue)
public class logentry {
public objectid id { get; set; } public datetime timestamp{ get; set; } public string level{ get; set; } public string logger{ get; set; } public string message{ get; set; }
}
why don't change
<name value="timestamp" />
with
<name value="timestamp" />
?
Comments
Post a Comment