c# - How can I set the database name using Serilog.Sink.MongoDB in appsettings.json in ASP.NET (Blazor)?
问题描述
I have Serilog set up to write to MongoDB via Serilog.Sinks.MongoDB
.
I'm using appsettings.json
for my configuration (with my password masked by XXXXXXX):
{
"Name": "MongoDB",
"Args": {
"databaseUrl": "mongodb+srv://AtlasUser:XXXXXXX/test?retryWrites=true&w=majority&ssl=true",
"databaseName": "MyLogs",
"collectionName": "MyLoggerCollection",
"cappedMaxSizeMb": "1024",
"cappedMaxDocuments": "50000"
}
This results in a database with the name test
and a collection called 'MyLoggerCollection'.
"databaseName": "MyLogs"
seems to be taking no effect.
The database created is still named test
(I guess the default?).
How can I set the database name to MyLogs
?
解决方案
You're specifying the database name as test
in your connection string, which is where the database name used comes from - not the databaseName
property.
"databaseUrl": "mongodb://username:password@ip:port**/dbName?authSource=admin"`
This should work:
{
"Name": "MongoDB",
"Args": {
"databaseUrl": "mongodb+srv://AtlasUser:XXXXXXX/MyLogs?retryWrites=true&w=majority&ssl=true",
"collectionName": "MyLoggerCollection",
"cappedMaxSizeMb": "1024",
"cappedMaxDocuments": "50000"
}
推荐阅读
- ag-grid - ag grid:排序后遍历所有行节点
- c# - 使用 UnityActions 或 C# Actions 时如何最好地避免内存泄漏
- javascript - 这个 async\await 代码在我的 Angular 应用程序中究竟是如何工作的?为什么 colled 方法没有显式返回 Promise?
- google-cloud-platform - 限制与 Cloud SQL MySQL 实例的连接
- prometheus - 如何使用prometheus和grafana查询百分比http请求
- spring-boot - Spring Boot 和 thymeleaf:无法评估 ArrayList 的 size()
- javascript - 打开页面,隐藏所有内容,除了 URL 说要打开的内容
- r - 如何在 R Shiny 中更改 DT Datable 标题的背景和文本颜色
- java - Android:如何在不使用 JavaX 的 ImageIO 的情况下获取图像的宽度和高度?
- javascript - 如何在 Flutter Android 应用程序的 HttpRequest 中访问上传的图像?