ChangemakerStudios / serilog-sinks-mongodb

A sink for Serilog that writes events to MongoDB
Apache License 2.0
90 stars 51 forks source link

Fixed invalid key characters preventing saving of logs #45

Closed DarkXoro closed 3 years ago

DarkXoro commented 5 years ago

I came across a bug in which the bson documents were not being saved to the database. Upon further testing I found out that while saving, the dictionary keys are not checked for invalid characters (. and $).

This fix aims to resolve this problem by passing the final string through a regex pattern meant to locate precisely these two characters in field names, and replace them with safe characters.

I faced this issue when I attached the current HttpContext to the log properties. The default cookie names (.AspNet.Consent, .AspNetCore.Session, .ga) were causing the issue since I was saving them as a dictionary.

PS: This fix is also attached to a closed (yet not fully fixed issue) found here.

IvaskevychYuriy commented 3 years ago

I think this one can be closed as fixed in referenced items. @nblumhardt

nblumhardt commented 3 years ago

Thanks @DarkXoro - sorry we were not able to get this one merged; the issue should be resolved now.