Closed vanamingo closed 3 years ago
Yep, I verified this as well. If you create the collection ahead of time with a cap in place, it works fine.
It's a workaround, but it'd be nice if it works out of the box.
I created a pull request to fix this issue. It would be quite great if it could be reviewed (https://github.com/serilog/serilog-sinks-mongodb/pull/54).
Fix is in latest dev.
I call:
Expected: MongoDBCapped method creates Capped collection. Actual: It doesn't create a capped collection. A common collection is created at the moment when some log writes to the collection.
Root cause description: I have debugged your code and found that MongoDBCapped method verifies if the collection already exists. If not, then it creates a capped collection. It seems that the following method is broken. database.GetCollection always return some object. And it always returns true even for nonexistent collection.
I use: MongoDB v 4.0.5 MongoDB driver 2.7.3
Serilog.AspNetCore 2.1.1 Serilog.Settings.Configuration 3.0.1 Serilog.Sinks.Console 3.1.1 Serilog.Sinks.ElasticSearch 7.1.0 Serilog.Sinks.MongoDB 4.0.0 Serilog.Sinks.SyslogServer 1.0.10