LogConfigurationExtensionsUseElasticSearchFromAppSettings Method
從 appsettings 載入 ElasticSearch 設定並啟用日誌目標
Namespace: eBizprise.Framework.Log.ElasticSearchAssembly: eBizprise.Framework.Log.LogHelper.ElasticSearch (in eBizprise.Framework.Log.LogHelper.ElasticSearch.dll) Version: 25.0.0.0+adf38c4ccb2bf98d8ad258a6278302b5e05a94ed
public static LogConfiguration UseElasticSearchFromAppSettings(
this LogConfiguration logConfiguration,
string configurationFileName = null,
string sectionName = "ElasticSearch",
LogLevel minLevel = null
)
- logConfiguration LogConfiguration
- 日誌配置物件
- configurationFileName String (Optional)
- 設定檔名稱 (可選,預設: appsettings.json)
- sectionName String (Optional)
- 設定區段名稱 (可選,預設: ElasticSearch)
- minLevel LogLevel (Optional)
- 最小日誌級別 (預設: Trace)
LogConfigurationLogConfiguration 物件 (支援鏈式呼叫)In Visual Basic and C#, you can call this method as an instance method on any object of type
LogConfiguration. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
appsettings.json 範例:
{
"ElasticSearch": {
"Uri": "https://192.168.128.116:9200",
"ProjectCode": "CAME002",
"ServerName": "ChemiCloud.Web",
"ApiKeyId": "jvw_3poBycV7S-uu4kaj",
"ApiKey": "Q-vth4PdT5im3AY1I8RWSw",
"IndexFormat": "",
"Username": "",
"Password": "",
"IncludeAllProperties": true,
"BatchSize": 100,
"ConnectionTimeout": 30,
"Layout": "${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"
}
}
// 使用預設設定檔 (appsettings.json) 和預設區段名稱 (ElasticSearch)
LogHelper.Configure(config =>
{
config.UseElasticSearchFromAppSettings();
});
// 指定自訂設定檔和區段名稱
LogHelper.Configure(config =>
{
config.UseElasticSearchFromAppSettings("myconfig.json", "Logging:ElasticSearch");
});
| Date | Version | Description |
|---|
| 2025/12/09 | 25.0.3.0 | 新增從 appsettings 自動載入設定功能 |