简体   繁体   English

如何在 ASP.NET (Blazor) 的 appsettings.json 中使用 Serilog.Sink.MongoDB 设置数据库名称?

[英]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 .我将 Serilog 设置为通过 Serilog.Sinks.MongoDB 写入Serilog.Sinks.MongoDB

I'm using appsettings.json for my configuration ( with my password masked by XXXXXXX ):我正在使用appsettings.json进行配置(我的密码被 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'.这会生成一个名为test的数据库和一个名为“MyLoggerCollection”的集合。

"databaseName": "MyLogs" seems to be taking no effect. "databaseName": "MyLogs"似乎无效。

The database created is still named test (I guess the default?).创建的数据库仍命名为test (我猜是默认值?)。

How can I set the database name to MyLogs ?如何将数据库名称设置为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.您在连接字符串中将数据库名称指定为test ,这是使用的数据库名称的来源- 而不是databaseName属性。

"databaseUrl": "mongodb://username:password@ip:port**/ dbName ?authSource=admin"` “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"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Serilog:RollingFile 在带有“appsettings.json”的 asp.net 核心中不起作用 - Serilog : RollingFile is not working in asp.net core with 'appsettings.json' asp.net core - 从 appsettings.json 设置 Serilog.Exceptions - asp.net core - Set Serilog.Exceptions from appsettings.json 如何使用 appsettings.json 在 Serilog 中禁用服务器证书验证? - How can I disable server certificate validation in Serilog using appsettings.json? 带有Asp.Net Core 2.1的Serilog不能从appsettings.json写入 - Serilog with Asp.Net Core 2.1 not writing from appsettings.json 将特定命名空间添加到 appsettings.json - Serilog ASP.NET Core 3.1 - Add Specfic Namespace to appsettings.json - Serilog ASP.NET Core 3.1 如何设置 appsettings.json 自动部署到 ASP.NET 核心? - How to set appsettings.json automatically for deployment in ASP.NET Core? 使用 Serilog 时如何覆盖 appsettings.json 中指定的应用程序名称? - How to overwrite application name specified in appsettings.json when using Serilog? Serilog 自定义接收器 - 使用 appsettings.json 设置最低级别不起作用 - Serilog custom sink - setting minimum level with appsettings.json not working 如何使用appsettings.json覆盖serilog设置 - How to override serilog settings using appsettings.json 将asp.net核心自包含Web应用程序部署到Ubuntu。 数据库名称在appsettings.json中存在时为空 - Deploying asp.net core self-contained web app to Ubuntu. Database name empty when present in appsettings.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM