LogConfigurationExtensionsUseFileLoggingFromAppSettings Method
從 appsettings 載入檔案日誌設定並啟用
Namespace: eBizprise.Framework.Log.ElasticSearchAssembly: eBizprise.Framework.Log.LogHelper.ElasticSearch (in eBizprise.Framework.Log.LogHelper.ElasticSearch.dll) Version: 25.0.3.0+6e92afb880fa099fdfe407c9aa8d1b17eaaf3625
public static LogConfiguration UseFileLoggingFromAppSettings(
this LogConfiguration logConfiguration,
string configurationFileName = null,
string sectionName = "FileLogging"
)
- logConfiguration LogConfiguration
- 日誌配置物件
- configurationFileName String (Optional)
- 設定檔名稱 (可選,預設: appsettings.json)
- sectionName String (Optional)
- 設定區段名稱 (可選,預設: FileLogging)
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 範例:
{
"FileLogging": {
"Layout": "${longdate} | GrpcUrl : ${aspnet-item:item=GrpcUrl} | Login UserId : ${aspnet-item:item=UserId} | TraceId : ${aspnet-TraceIdentifier:ignoreActivityId=true} | ${message} ${onexception:${newline}${exception:format=tostring}}",
"FileName": "${basedir}/../ChemiCloud.Service.Logs/${level:lowercase=true}.log",
"ArchiveFileName": "${basedir}/../ChemiCloud.Service.Logs/Backup/${level}.${shortdate}.log",
"ArchiveEvery": "Day",
"ArchiveAboveSize": 10485760,
"MaxArchiveDays": 90,
"MaxArchiveFiles": 30,
"KeepFileOpen": true,
"Encoding": "UTF-8"
}
}
// 使用預設設定檔和預設區段名稱
LogHelper.Configure(config =>
{
config.UseFileLoggingFromAppSettings();
});
// 指定自訂設定檔和區段名稱
LogHelper.Configure(config =>
{
config.UseFileLoggingFromAppSettings("myconfig.json", "Logging:File");
});
| Date | Version | Description |
|---|
| 2025/12/16 | 25.0.3.0 | 新增從 appsettings 載入檔案日誌設定功能 |