{"id":28393390,"url":"https://github.com/changemakerstudios/serilog-sinks-mongodb","last_synced_at":"2025-07-07T03:09:56.231Z","repository":{"id":26675978,"uuid":"30132627","full_name":"ChangemakerStudios/serilog-sinks-mongodb","owner":"ChangemakerStudios","description":"A sink for Serilog that writes events to MongoDB","archived":false,"fork":false,"pushed_at":"2024-11-05T14:48:58.000Z","size":179,"stargazers_count":95,"open_issues_count":3,"forks_count":50,"subscribers_count":10,"default_branch":"dev","last_synced_at":"2025-06-01T03:10:29.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChangemakerStudios.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-01T01:27:11.000Z","updated_at":"2025-05-21T13:27:33.000Z","dependencies_parsed_at":"2024-02-18T00:26:09.992Z","dependency_job_id":"70709f89-09dd-4f41-81e2-c75642e48b3b","html_url":"https://github.com/ChangemakerStudios/serilog-sinks-mongodb","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/ChangemakerStudios/serilog-sinks-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChangemakerStudios%2Fserilog-sinks-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChangemakerStudios%2Fserilog-sinks-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChangemakerStudios%2Fserilog-sinks-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChangemakerStudios%2Fserilog-sinks-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChangemakerStudios","download_url":"https://codeload.github.com/ChangemakerStudios/serilog-sinks-mongodb/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChangemakerStudios%2Fserilog-sinks-mongodb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264005558,"owners_count":23542834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-31T16:10:01.667Z","updated_at":"2025-07-07T03:09:56.222Z","avatar_url":"https://github.com/ChangemakerStudios.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![mongo icon](https://raw.githubusercontent.com/ChangemakerStudios/serilog-sinks-mongodb/dev/assets/mongo-icon.png) Serilog.Sinks.MongoDB\n\n[![NuGet version](https://badge.fury.io/nu/Serilog.Sinks.MongoDB.svg)](https://badge.fury.io/nu/Serilog.Sinks.MongoDB)\n[![Downloads](https://img.shields.io/nuget/dt/Serilog.Sinks.MongoDB.svg?logo=nuget\u0026color=purple)](https://www.nuget.org/packages/Serilog.Sinks.MongoDB) \n[![Build status](https://github.com/ChangemakerStudios/serilog-sinks-mongodb/actions/workflows/deploy.yml/badge.svg)](https://github.com/ChangemakerStudios/serilog-sinks-mongodb/actions) \n\nA Serilog sink that writes events as documents to [MongoDB](http://mongodb.org).\n\n**Package** - [Serilog.Sinks.MongoDB](http://nuget.org/packages/serilog.sinks.mongodb)\n**Platforms** - .NET 4.7.2, .NET 6.0, .NET Standard 2.1\n\n## Whats New\n\n#### New in v7.x\n* Upgrade MongoDB.Driver to v3.0 - .NET Standard 2.0 support has been removed.\n\n#### New in v6.x\n* Upgrade MongoDB.Driver to v2.28.0 (Thanks to [Memoyu](https://github.com/Memoyu))\n* Add trace context to LogEntry (Thanks to [fernandovmp](https://github.com/fernandovmp))\n\n#### New in v5.x\n* 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.\n* Rolling Log Collection Naming (Thanks to [Revazashvili](https://github.com/Revazashvili) for the PR!). MongoDBBson sink only.\n* Expire TTL support. MongoDBBson sink only.\n\n## Installation\nInstall the sink via NuGet Package Manager Console:\n\n```powershell\nInstall-Package Serilog.Sinks.MongoDB\n```\n\nor via the .NET CLI:\n\n```bash\ndotnet add package Serilog.Sinks.MongoDB\n```\n\n## Usage Examples\nIn 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.\n\n### Basic:\n```csharp\nusing Serilog;\n\n// use BSON structured logs\nvar log = new LoggerConfiguration()\n    .WriteTo.MongoDBBson(\"mongodb://mymongodb/logs\")\n    .CreateLogger();\n\nlog.Information(\"This is a test log message\");\n```\n\n### Capped Collection:\n\n```csharp\n// capped collection using BSON structured logs\nvar log = new LoggerConfiguration()\n    .WriteTo.MongoDBBson(\"mongodb://mymongodb/logs\", cfg =\u003e\n    {\n        // optional configuration options:\n        cfg.SetCollectionName(\"log\");\n        cfg.SetBatchPeriod(TimeSpan.FromSeconds(1));\n\n        // create capped collection that is max 100mb\n        cfg.SetCreateCappedCollection(100);\n    })\n    .CreateLogger();\n```\n\n### Custom Mongodb Settings:\n```csharp\n// create sink instance with custom mongodb settings.\nvar log = new LoggerConfiguration()\n\t.WriteTo.MongoDBBson(cfg =\u003e\n    {\n\t\t// custom MongoDb configuration\n\t\tvar mongoDbSettings = new MongoClientSettings\n\t\t{\n\t\t\tUseTls = true,\t\t\t\n\t\t\tAllowInsecureTls = true,\n\t\t\tCredential = MongoCredential.CreateCredential(\"databaseName\", \"username\", \"password\"),\n\t\t\tServer = new MongoServerAddress(\"127.0.0.1\")\n\t\t};\n\n\t\tvar mongoDbInstance = new MongoClient(mongoDbSettings).GetDatabase(\"serilog\");\n\t\t\n\t\t// sink will use the IMongoDatabase instance provided\n\t\tcfg.SetMongoDatabase(mongoDbInstance);\n\t\tcfg.SetRollingInternal(RollingInterval.Month);\n    })\n\t.CreateLogger();\n```\n### JSON (_Microsoft.Extensions.Configuration_)\n\nKeys and values are not case-sensitive. This is an example of configuring the MongoDB sink arguments from _Appsettings.json_:\n\n```json\n{\n  \"Serilog\": {\n    \"MinimumLevel\": {\n      \"Default\": \"Information\",\n      \"Override\": {\n        \"Microsoft\": \"Error\",\n        \"System\": \"Warning\"\n      }\n    },\n    \"WriteTo\": [\n      { \n      \t\"Name\": \"MongoDBBson\", \n        \"Args\": { \n            \"databaseUrl\": \"mongodb://username:password@ip:port/dbName?authSource=admin\",\n            \"collectionName\": \"logs\",\n            \"cappedMaxSizeMb\": \"1024\",\n            \"cappedMaxDocuments\": \"50000\",\n            \"rollingInterval\": \"Month\"\n        }\n      } \n    ]\n  }\n}\n```\n\n## Icon\n\n[MongoDB](https://icons8.com/icon/74402/mongodb) icon by [Icons8](https://icons8.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangemakerstudios%2Fserilog-sinks-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchangemakerstudios%2Fserilog-sinks-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchangemakerstudios%2Fserilog-sinks-mongodb/lists"}