I have a local MongoDb database instance (created by running mongod from the Windows command line), and a simple console program that tries to log a string to the MongoDb database using Serilog and its MongoDb sink:
var log = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.ColoredConsole()
.WriteTo.MongoDB("mongodb://localhost/mydb")
.CreateLogger();
log.Fatal("Fatal message");
The "Fatal message" message is written correctly to the console, but not to my MongoDb database.
My current MongoDb database is "mydb". According to "show collections", I only have collections system.indexes and testData, and "db.testData.find()" produces nothing.
The Serilog site says to use connection string "mongo://mydb/log", but that throws an exception "An unhandled exception of type 'System.FormatException' occurred in MongoDB.Driver.dll". The connection string I used in my code is specified on the MongoDb site, at http://docs.mongodb.org/manual/reference/connection-string/
How can I log to MongoDb using Serilog?