Serilog.Sinks.MongoDB 7.0.0

dotnet add package Serilog.Sinks.MongoDB --version 7.0.0
                    
NuGet\Install-Package Serilog.Sinks.MongoDB -Version 7.0.0
                    
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="7.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Sinks.MongoDB" Version="7.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Serilog.Sinks.MongoDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Serilog.Sinks.MongoDB --version 7.0.0
                    
#r "nuget: Serilog.Sinks.MongoDB, 7.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Serilog.Sinks.MongoDB&version=7.0.0
                    
Install Serilog.Sinks.MongoDB as a Cake Addin
#tool nuget:?package=Serilog.Sinks.MongoDB&version=7.0.0
                    
Install Serilog.Sinks.MongoDB as a Cake Tool

mongo icon Serilog.Sinks.MongoDB

NuGet version Downloads Build status

A Serilog sink that writes events as documents to MongoDB.

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

Whats New

New in v7.x
  • Upgrade MongoDB.Driver to v3.0 - .NET Standard 2.0 support has been removed.
New in v6.x
  • Upgrade MongoDB.Driver to v2.28.0 (Thanks to Memoyu)
  • Add trace context to LogEntry (Thanks to fernandovmp)
New in v5.x
  • Output structured MongoDB Bson logs by switching to .MongoDBBson() extensions. Existing .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.

Installation

Install the sink via NuGet Package Manager Console:

Install-Package Serilog.Sinks.MongoDB

or via the .NET CLI:

dotnet add package Serilog.Sinks.MongoDB

Usage Examples

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.

Basic:

using Serilog;

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

log.Information("This is a test log message");

Capped Collection:

// 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();

Custom Mongodb Settings:

// 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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (51)

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

Package Downloads
RG3.PF.Web.StartUsed

1、【核心业务使用包RG3.PF.Web.StartUsed】(可配置化,标准化,灵活配置,集成百度、腾讯、阿里、短信通等巨头接口,可脱离开发环境,集成nodejs中间件、统一认证中心) 2、以Rg3.开头且类继承 IService 或 IRepository的在Starup里面不用注入,案例如下 3、public class ListRepository : IRepository 4、public class ListService : IService 5、使用请到github获取 RG3.PF.WebApp.Host 6、Quartz集成redis订阅、Quartz 7、修复多引用CLDC 8、接入微信公众号wxconfig 9、Prometheus+Grafana https://doc.rg1008.com/docs/rg_pass_log/rg_pass_log-1dpcuns9s6r8c 10、Headers添加VerifyApiValue 用于验证 11、添加时间戳 Convert.ToInt64(DateTimePFUtil.ToTimestampSecond(this.Expires)); 12、版本记录:https://doc.rg1008.com/docs/rg_pass_log/rg_pass_log-1dpubsabl25v4 13、 20240815 升级到.netcore sdk 8.0

TianCheng.Model

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

Basic.Logging.Serilog

Package Description

uBeac.Logging.MongoDB

Easily implement logging with MongoDB in your .NET projects!

PegasusLoggingService

Package Description

GitHub repositories (2)

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

Repository Stars
serilog-contrib/serilog-ui
Simple Serilog log viewer UI for several sinks.
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
7.0.0 150,178 11/5/2024
6.0.0 83,683 9/20/2024
5.4.1 310,640 2/18/2024
5.3.1 1,021,121 9/28/2022
5.2.2 7,284 9/26/2022
5.2.1 31,767 9/3/2022
5.2.1-tags-v5-2-0-0000 320 9/3/2022
5.2.0 803 9/3/2022
5.1.5 295,420 4/24/2022
5.1.2 172,916 1/19/2022
5.1.2-dev-00124 344 3/12/2022
5.1.2-dev-00123 579 1/19/2022
5.1.2-dev-00121 554 1/19/2022
5.1.1 253,268 9/25/2021
5.1.1-dev-00120 596 1/19/2022
5.1.1-dev-00119 542 1/19/2022
5.1.1-dev-00118 577 1/19/2022
5.1.1-dev-00116 406 9/25/2021
5.1.0-dev-00114 429 9/25/2021
5.0.0 79,114 9/2/2021
5.0.0-dev-00112 477 9/24/2021
5.0.0-dev-00111 501 9/12/2021
5.0.0-dev-00110 475 9/12/2021
5.0.0-dev-00109 438 9/2/2021
5.0.0-dev-00107 422 9/2/2021
5.0.0-dev-00105 720 8/1/2021
5.0.0-dev-00104 1,925 5/8/2021
5.0.0-dev-00103 495 5/7/2021
5.0.0-dev-00100 22,586 5/6/2021
5.0.0-dev-00099 492 5/6/2021
5.0.0-dev-00098 471 5/6/2021
5.0.0-dev-00097 849 5/6/2021
4.1.0 404,128 5/6/2021
4.1.0-dev-00096 487 5/6/2021
4.1.0-dev-00094 463 5/6/2021
4.1.0-dev-00084 10,548 10/21/2020
4.1.0-dev-00069 19,923 1/29/2019
4.0.0 1,645,845 11/9/2018
4.0.0-dev-00068 595 1/29/2019
4.0.0-dev-00064 690 11/9/2018
4.0.0-dev-00062 7,391 2/15/2018
4.0.0-dev-00060 1,139 11/30/2017
3.1.1-dev-00059 924 11/30/2017
3.1.0 503,086 11/1/2016
3.1.0-dev-00049 1,108 10/30/2016
3.1.0-dev-00046 1,564 10/7/2016
3.1.0-dev-00044 989 10/7/2016
3.1.0-dev-00042 989 10/5/2016
3.1.0-dev-00037 1,041 10/5/2016
3.1.0-dev-00035 1,022 9/9/2016
3.1.0-dev-00033 982 9/8/2016
3.0.0 3,051 8/9/2016
3.0.0-dev-00030 1,004 8/9/2016
3.0.0-dev-00029 974 8/9/2016
3.0.0-beta-24 1,399 4/26/2016
2.0.19 12,898 2/16/2016
2.0.18 1,310 2/16/2016
2.0.14 22,817 1/26/2016
2.0.13 4,340 7/26/2015
2.0.11 2,232 4/18/2015
2.0.8-pre 1,113 4/2/2015
2.0.7-pre 1,072 3/26/2015
2.0.6-pre 1,060 3/16/2015
2.0.3-pre 1,070 3/10/2015
2.0.1-pre 1,078 2/1/2015
2.0.0-beta-27 974 5/6/2016
1.4.139 2,037 1/23/2015
1.4.118 1,321 1/13/2015
1.4.113 1,443 1/6/2015
1.4.102 1,805 12/21/2014
1.4.99 1,712 12/18/2014
1.4.97 1,563 12/18/2014
1.4.76 1,659 12/8/2014
1.4.39 1,530 11/26/2014
1.4.34 1,488 11/24/2014
1.4.28 1,542 11/24/2014
1.4.27 1,560 11/23/2014
1.4.23 1,667 11/21/2014
1.4.21 1,553 11/21/2014
1.4.18 1,635 11/18/2014
1.4.15 2,592 11/4/2014
1.4.14 1,489 10/23/2014
1.4.13 1,361 10/23/2014
1.4.12 1,455 10/12/2014
1.4.11 1,401 10/8/2014
1.4.10 1,416 9/26/2014
1.4.9 1,496 9/17/2014
1.4.8 1,416 9/11/2014
1.4.7 1,456 9/1/2014
1.4.6 1,368 8/31/2014
1.4.5 1,527 8/27/2014
1.4.4 1,404 8/27/2014
1.4.3 1,507 8/25/2014
1.4.2 1,428 8/23/2014
1.4.1 1,408 8/23/2014
1.3.43 1,676 8/4/2014
1.3.42 1,436 7/30/2014
1.3.41 1,412 7/28/2014
1.3.40 1,348 7/26/2014
1.3.39 1,372 7/25/2014
1.3.36 1,383 7/20/2014
1.3.35 1,367 7/17/2014
1.3.34 2,050 7/6/2014
1.3.33 1,376 6/30/2014
1.3.30 1,432 6/19/2014
1.3.29 1,424 6/19/2014
1.3.28 1,367 6/19/2014
1.3.27 1,406 6/18/2014
1.3.25 1,440 6/9/2014
1.3.24 1,486 5/21/2014
1.3.23 1,388 5/20/2014
1.3.20 1,433 5/18/2014
1.3.19 1,376 5/17/2014
1.3.18 1,352 5/17/2014
1.3.17 1,359 5/17/2014
1.3.16 1,385 5/17/2014
1.3.15 1,377 5/16/2014
1.3.14 1,478 5/16/2014
1.3.13 1,375 5/16/2014
1.3.12 1,385 5/14/2014
1.3.7 1,401 5/11/2014
1.3.6 1,410 5/9/2014
1.3.5 1,396 5/6/2014
1.3.4 1,513 5/4/2014
1.3.3 1,591 4/28/2014
1.3.1 1,418 4/26/2014
1.2.53 1,440 4/26/2014
1.2.52 1,670 4/24/2014
1.2.51 1,601 4/18/2014
1.2.50 1,541 4/18/2014
1.2.49 1,538 4/17/2014
1.2.48 1,518 4/14/2014
1.2.47 1,629 4/14/2014
1.2.45 1,668 4/13/2014
1.2.44 1,571 4/9/2014
1.2.41 1,509 4/7/2014
1.2.40 1,497 4/7/2014
1.2.39 1,464 3/29/2014
1.2.37 1,491 3/29/2014
1.2.29 1,505 3/16/2014
1.2.26 1,418 3/12/2014
1.2.25 1,464 2/20/2014
0.9.9 1,578 11/23/2013
0.9.1 1,551 8/24/2013
0.8.5 1,578 7/22/2013
0.8.1 1,620 7/9/2013
0.7.2 1,627 7/6/2013
0.6.1 1,574 6/13/2013
0.5.2 1,527 5/27/2013
0.5.1 1,527 5/26/2013
0.4.3 1,533 5/25/2013
0.3.2 1,491 5/19/2013
0.3.1 1,473 5/19/2013
0.2.10 1,528 5/13/2013
0.2.9 1,456 5/10/2013
0.2.7 1,437 5/8/2013
0.2.6 1,517 5/8/2013
0.2.5 1,489 5/7/2013
0.2.1 1,529 4/8/2013
0.1.18 1,539 4/6/2013
0.1.17 1,479 4/4/2013
0.1.16 1,508 4/3/2013
0.1.12 1,532 4/1/2013
0.1.11 2,923 3/30/2013

v7.0 - Upgraded to MongoDB.Driver to version 3.0 fixing incompatibilities.