当前位置:网站首页>ASP. Net core reads the configuration file in the class library project
ASP. Net core reads the configuration file in the class library project
2022-04-23 17:04:00 【begeneral】
Go straight to the code :
public static string ReadConnectString(string connectName)
{
var config = new ConfigurationBuilder().Add(new JsonConfigurationSource()
{
Path = "appsettings.json",
Optional = true
}).Build();
var connectionString = config.GetConnectionString(connectName);
if(string.IsNullOrEmpty(connectionString))
{
LogHelper.WriteErrorLog($" stay appsettings.json in , Could not find name {connectName} Connection string of ");
return null;
}
return connectionString;
}
The configuration file is as follows :
{
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database= Database name ;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Follow this configuration file , The parameter passed in by the above function should be :DefaultConnection.
I want to introduce 2 An assembly :
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
What I write here is read only appsettings.json The connection string inside , If you want to read the custom configuration , Call GetSection.
版权声明
本文为[begeneral]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554082264.html
边栏推荐
- Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
- _ Mold_ Board_
- Milvus 2.0 质量保障系统详解
- 面试百分百问到的进程,你究竟了解多少
- Regular filtering of Intranet addresses and segments
- Generate random numbers with high quality and Gaussian distribution
- Multithreaded @ async thread pool
- ◰GL-阴影贴图核心步骤
- PostgreSQL column storage and row storage
- Production environment——
猜你喜欢

oracle 中快速获取表的列名列表

English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)

Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme

Idea of batch manufacturing test data, with source code

【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明

详解牛客----手套

vscode如何比较两个文件的异同
![Knowledge points and examples of [seven input / output systems]](/img/5f/759a73836f79ef848f449930dcc1b1.png)
Knowledge points and examples of [seven input / output systems]

How to build tiktok user trust and drive fan growth

Detailed explanation of Niuke - Gloves
随机推荐
RTKLIB 2.4.3源码笔记
MySQL restores data through binlog file
Expression "func" tSource, object "to expression" func "tSource, object" []
线性代数感悟之1
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
◰ GL shader handler encapsulation
On lambda powertools typescript
自定义my_strcpy与库strcpy【模拟实现字符串相关函数】
VsCode-Go
1-4 configuration executable script of nodejs installation
Website_ Collection
Shell脚本——Shell编程规范及变量
Wiper component encapsulation
Go language RPC communication
PyMySQL
PHP高效读大文件处理数据
How much do you know about the process of the interview
PostgreSQL列存与行存
Promise (I)