A Serilog sink that writes events as documents to MongoDB.
Package - Serilog.Sinks.MongoDB | Platforms - .NET 4.6
You'll need to create a collection on your MongoDB server. In the example shown, the database in use is called logs
. The collection name is log
and is created implicitely.
var log = new LoggerConfiguration()
.WriteTo.MongoDB("mongodb://mymongodb/logs")
.CreateLogger();
Additionally you can utilize a Capped Collection. This type allows explicit collection naming.
var log = new LoggerConfiguration()
.WriteTo.MongoDBCapped("mongodb://mymongodb/logs", collectionName: "customCollectionName")
.CreateLogger();