Serilog.Sinks.MongoDB 5.3.1

.NET Standard 2.0 .NET Framework 4.7.2
dotnet add package Serilog.Sinks.MongoDB --version 5.3.1
NuGet\Install-Package Serilog.Sinks.MongoDB -Version 5.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.MongoDB" Version="5.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Sinks.MongoDB --version 5.3.1
#r "nuget: Serilog.Sinks.MongoDB, 5.3.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Serilog.Sinks.MongoDB as a Cake Addin
#addin nuget:?package=Serilog.Sinks.MongoDB&version=5.3.1

// Install Serilog.Sinks.MongoDB as a Cake Tool
#tool nuget:?package=Serilog.Sinks.MongoDB&version=5.3.1

mongo icon Serilog.Sinks.MongoDB

Build status

A Serilog sink that writes events as documents to MongoDB.

Package - Serilog.Sinks.MongoDB | Platforms - .NET 4.7.2, .NET Standard 2.0,, .NET Standard 2.1

New in v5.x

  • Output structured MongoDB Bson logs by switching to the .MongoDBBson() extensions. Existing the .MongoDB() extensions will continue to work converting logs to Json and then to Bson.
  • Rolling Log Collection Naming (Thanks to Revazashvili for the PR!). MongoDBBson sink only.
  • Expire TTL support. MongoDBBson sink only.

Configuration

In the examples below, the sink is writing to the database logs with structured Bson. 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.

// use Bson structured logs
var log = new LoggerConfiguration()
    .WriteTo.MongoDBBson("mongodb://mymongodb/logs")
    .CreateLogger();

// capped collection using Bson structured logs
var log = new LoggerConfiguration()
    .WriteTo.MongoDBBson("mongodb://mymongodb/logs", cfg =>
    {
        // optional configuration options:
        cfg.SetCollectionName("log");
        cfg.SetBatchPeriod(TimeSpan.FromSeconds(1));

        // create capped collection that is max 100mb
        cfg.SetCreateCappedCollection(100);
    })
    .CreateLogger();

// create sink instance with custom mongodb settings.
var log = new LoggerConfiguration()
	.WriteTo.MongoDBBson(cfg =>
    {
		// custom MongoDb configuration
		var mongoDbSettings = new MongoClientSettings
		{
			UseTls = true,			
			AllowInsecureTls = true,
			Credential = MongoCredential.CreateCredential("databaseName", "username", "password"),
			Server = new MongoServerAddress("127.0.0.1")
		};

		var mongoDbInstance = new MongoClient(mongoDbSettings).GetDatabase("serilog");
		
		// sink will use the IMongoDatabase instance provided
		cfg.SetMongoDatabase(mongoDbInstance);
		cfg.SetRollingInternal(RollingInterval.Month);
    })
	.CreateLogger();

JSON (Microsoft.Extensions.Configuration)

Keys and values are not case-sensitive. This is an example of configuring the MongoDB sink arguments from Appsettings.json:

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Error",
        "System": "Warning"
      }
    },
    "WriteTo": [
      { 
      	"Name": "MongoDBBson", 
        "Args": { 
            "databaseUrl": "mongodb://username:password@ip:port/dbName?authSource=admin",
            "collectionName": "logs",
            "cappedMaxSizeMb": "1024",
            "cappedMaxDocuments": "50000",
            "rollingInterval": "Month"
        }
      } 
    ]
  }
}

Icon

MongoDB icon by Icons8

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (28)

Showing the top 5 NuGet packages that depend on Serilog.Sinks.MongoDB:

Package Downloads
TianCheng.Model

实体对象基类,及其常用操作。 常用操作包括:对象转换、序列化、日志、常用异常处理、依赖注入。

Basic.Logging.Serilog

Package Description

uBeac.Logging.MongoDB

Easily implement logging with MongoDB in your .NET projects!

Atlas.Framework.Web

Package Description

LShared.Frameworks

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Serilog.Sinks.MongoDB:

Repository Stars
DevArchitecture/DevArchitecture
DevArchitecture Backend Project
keremvaris/Sennedjem
Sennedjem CQRS (Command Query Responsibility Segregation) yaklaşımını benimseyen ve SOLID prensiplerini ve Clean Architecture yöntemlerini odaklayan bir yazılım geliştirme alt yapısıdır. RabbitMq, ElasticSearch vb araçlara entegre olmak konusunda çok yeteneklidir.
Version Downloads Last updated
5.3.1 18,056 9/28/2022
5.2.2 750 9/26/2022
5.2.1 12,464 9/3/2022
5.2.1-tags-v5-2-0-0000 57 9/3/2022
5.2.0 167 9/3/2022
5.1.5 88,569 4/24/2022
5.1.2 76,831 1/19/2022
5.1.2-dev-00124 77 3/12/2022
5.1.2-dev-00123 92 1/19/2022
5.1.2-dev-00121 94 1/19/2022
5.1.1 161,094 9/25/2021
5.1.1-dev-00120 95 1/19/2022
5.1.1-dev-00119 94 1/19/2022
5.1.1-dev-00118 92 1/19/2022
5.1.1-dev-00116 168 9/25/2021
5.1.0-dev-00114 162 9/25/2021
5.0.0 49,889 9/2/2021
5.0.0-dev-00112 220 9/24/2021
5.0.0-dev-00111 229 9/12/2021
5.0.0-dev-00110 203 9/12/2021
5.0.0-dev-00109 171 9/2/2021
5.0.0-dev-00107 176 9/2/2021
5.0.0-dev-00105 366 8/1/2021
5.0.0-dev-00104 1,452 5/8/2021
5.0.0-dev-00103 221 5/7/2021
5.0.0-dev-00100 8,078 5/6/2021
5.0.0-dev-00099 224 5/6/2021
5.0.0-dev-00098 188 5/6/2021
5.0.0-dev-00097 473 5/6/2021
4.1.0 207,371 5/6/2021
4.1.0-dev-00096 208 5/6/2021
4.1.0-dev-00094 197 5/6/2021
4.1.0-dev-00084 9,235 10/21/2020
4.1.0-dev-00069 12,704 1/29/2019
4.0.0 1,145,992 11/9/2018
4.0.0-dev-00068 442 1/29/2019
4.0.0-dev-00064 527 11/9/2018
4.0.0-dev-00062 6,947 2/15/2018
4.0.0-dev-00060 875 11/30/2017
3.1.1-dev-00059 685 11/30/2017
3.1.0 383,140 11/1/2016
3.1.0-dev-00049 854 10/30/2016
3.1.0-dev-00046 1,270 10/7/2016
3.1.0-dev-00044 727 10/7/2016
3.1.0-dev-00042 736 10/5/2016
3.1.0-dev-00037 783 10/5/2016
3.1.0-dev-00035 757 9/9/2016
3.1.0-dev-00033 720 9/8/2016
3.0.0 2,306 8/9/2016
3.0.0-dev-00030 748 8/9/2016
3.0.0-dev-00029 724 8/9/2016
3.0.0-beta-24 1,136 4/26/2016
2.0.19 12,296 2/16/2016
2.0.18 918 2/16/2016
2.0.14 22,398 1/26/2016
2.0.13 3,933 7/26/2015
2.0.11 1,839 4/18/2015
2.0.8-pre 842 4/2/2015
2.0.7-pre 793 3/26/2015
2.0.6-pre 787 3/16/2015
2.0.3-pre 790 3/10/2015
2.0.1-pre 810 2/1/2015
2.0.0-beta-27 730 5/6/2016
1.4.139 1,577 1/23/2015
1.4.118 945 1/13/2015
1.4.113 1,056 1/6/2015
1.4.102 1,431 12/21/2014
1.4.99 1,322 12/18/2014
1.4.97 1,162 12/18/2014
1.4.76 1,252 12/8/2014
1.4.39 1,125 11/26/2014
1.4.34 1,084 11/24/2014
1.4.28 1,136 11/24/2014
1.4.27 1,132 11/23/2014
1.4.23 1,238 11/21/2014
1.4.21 1,153 11/21/2014
1.4.18 1,240 11/18/2014
1.4.15 2,222 11/4/2014
1.4.14 1,113 10/23/2014
1.4.13 949 10/23/2014
1.4.12 1,049 10/12/2014
1.4.11 965 10/8/2014
1.4.10 983 9/26/2014
1.4.9 1,071 9/17/2014
1.4.8 1,014 9/11/2014
1.4.7 1,057 9/1/2014
1.4.6 981 8/31/2014
1.4.5 1,121 8/27/2014
1.4.4 980 8/27/2014
1.4.3 1,070 8/25/2014
1.4.2 998 8/23/2014
1.4.1 987 8/23/2014
1.3.43 1,228 8/4/2014
1.3.42 1,007 7/30/2014
1.3.41 987 7/28/2014
1.3.40 948 7/26/2014
1.3.39 974 7/25/2014
1.3.36 978 7/20/2014
1.3.35 964 7/17/2014
1.3.34 1,174 7/6/2014
1.3.33 972 6/30/2014
1.3.30 990 6/19/2014
1.3.29 993 6/19/2014
1.3.28 986 6/19/2014
1.3.27 1,019 6/18/2014
1.3.25 1,045 6/9/2014
1.3.24 1,058 5/21/2014
1.3.23 967 5/20/2014
1.3.20 1,013 5/18/2014
1.3.19 977 5/17/2014
1.3.18 953 5/17/2014
1.3.17 959 5/17/2014
1.3.16 981 5/17/2014
1.3.15 963 5/16/2014
1.3.14 1,051 5/16/2014
1.3.13 968 5/16/2014
1.3.12 967 5/14/2014
1.3.7 997 5/11/2014
1.3.6 994 5/9/2014
1.3.5 983 5/6/2014
1.3.4 1,105 5/4/2014
1.3.3 1,173 4/28/2014
1.3.1 999 4/26/2014
1.2.53 993 4/26/2014
1.2.52 1,228 4/24/2014
1.2.51 1,195 4/18/2014
1.2.50 1,151 4/18/2014
1.2.49 1,124 4/17/2014
1.2.48 1,110 4/14/2014
1.2.47 1,189 4/14/2014
1.2.45 1,241 4/13/2014
1.2.44 1,148 4/9/2014
1.2.41 1,086 4/7/2014
1.2.40 1,091 4/7/2014
1.2.39 1,051 3/29/2014
1.2.37 1,064 3/29/2014
1.2.29 1,089 3/16/2014
1.2.26 1,036 3/12/2014
1.2.25 1,073 2/20/2014
0.9.9 1,137 11/23/2013
0.9.1 1,141 8/24/2013
0.8.5 1,148 7/22/2013
0.8.1 1,172 7/9/2013
0.7.2 1,210 7/6/2013
0.6.1 1,154 6/13/2013
0.5.2 1,117 5/27/2013
0.5.1 1,110 5/26/2013
0.4.3 1,104 5/25/2013
0.3.2 1,072 5/19/2013
0.3.1 1,050 5/19/2013
0.2.10 1,108 5/13/2013
0.2.9 1,048 5/10/2013
0.2.7 1,038 5/8/2013
0.2.6 1,087 5/8/2013
0.2.5 1,067 5/7/2013
0.2.1 1,068 4/8/2013
0.1.18 1,082 4/6/2013
0.1.17 1,076 4/4/2013
0.1.16 1,092 4/3/2013
0.1.12 1,109 4/1/2013
0.1.11 1,205 3/30/2013