Purge Old Mongo Logs without User Intervention

jieforest發表於2012-05-28

One of thecoolest feature of Mongo is the concept of Capped Collection, or “fixed size” collection. They are based ona FIFO queue where the first record to be discharded is the first inserted, andthis is exceptional to create a log-collection that automatically purge all oldlogs without any user intervention.


To be ableto automatically enable this feature on the Log4Net Mongo appender you need to do a little modification to thecode, this is because the original code simply gets a reference to thecollection with this code.

CODE:

connection = MongoServer.Create(mongoConnectionString.ToString());
connection.Connect();
var db = connection.GetDatabase(DatabaseName);
collection = db.GetCollection(CollectionName);






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-731251/,如需轉載,請註明出處,否則將追究法律責任。

相關文章