Skip to content

pberggreen/serilog-sinks-mongodb

 
 

Repository files navigation

Serilog.Sinks.MongoDB

Build status

A Serilog sink that writes events as documents to MongoDB.

Package - Serilog.Sinks.MongoDB | Platforms - .NET 4.6, .NETStandard 1.5

In the example shown, the sink will write to the database logs. The default collection name is log, but a custom collection can be supplied with the optional CollectionName parameter. The database and collection will be created if they do not exist.

// basic usage defaults to writing to `log` collection
var log = new LoggerConfiguration()
    .WriteTo.MongoDB("mongodb://mymongodb/logs")
    .CreateLogger();

// creates custom collection `applog`
var log = new LoggerConfiguration()
    .WriteTo.MongoDB("mongodb://mymongodb/logs", collectionName: "applog")
    .CreateLogger();

Additionally, you can utilize a Capped Collection.

// basic with custom collection name
var log = new LoggerConfiguration()
    .WriteTo.MongoDBCapped("mongodb://mymongodb/logs", collectionName: "rollingapplog")
    .CreateLogger();

// optional parameters cappedMaxSizeMb and cappedMaxDocuments specified
var log = new LoggerConfiguration()
    .WriteTo.MongoDBCapped("mongodb://mymongodb/logs", cappedMaxSizeMb: 50, cappedMaxDocuments: 1000)
    .CreateLogger();

About

A sink for Serilog that writes events to MongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 95.3%
  • PowerShell 4.7%