我們知道我們可以使用 IConfiguration 類的 GetSection 方法從 json 中獲取值,或者configuration["Serilog:Properties:ApplicationName"];在陣列的情況下簡單地使用configuration.GetSection("Serilog.Enrich").Get<string[]>()
但我不知道如何檢索嵌套在 WriteTo 陣列的第一個節點中的“serverUrl”鍵的值
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning",
"Serilog": "Warning"
}
},
"Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ],
"Properties": {
"ApplicationName": "MyApp"
},
"WriteTo": [
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341"
}
}
]
}
有什么建議嗎?
uj5u.com熱心網友回復:
試試這個
var serverUrl = configuration.GetSection("Serilog").GetSection("WriteTo")
.Get<Dictionary<string,Dictionary<string,string>>[]>()[0]["Args"]["serverUrl"];
或使用 c# 類
var serverUrl = configuration.GetSection("Serilog").GetSection("WriteTo")
.Get<WriteTo[]>()[0].Args.serverUrl;
班級
public partial class WriteTo
{
public string Name { get; set; }
public Args Args { get; set; }
}
public partial class Args
{
public Uri serverUrl { get; set; }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/474280.html
上一篇:使用linqASP.NETMVC按兩個屬性分組的回傳串列
下一篇:如何更改asp.net中的視圖?
