LogConfigurationExtensionsUseFileLoggingFromAppSettings Method

從 appsettings 載入檔案日誌設定並啟用

Definition

Namespace: eBizprise.Framework.Log.ElasticSearch
Assembly: eBizprise.Framework.Log.LogHelper.ElasticSearch (in eBizprise.Framework.Log.LogHelper.ElasticSearch.dll) Version: 25.0.3.0+6e92afb880fa099fdfe407c9aa8d1b17eaaf3625
C#
public static LogConfiguration UseFileLoggingFromAppSettings(
	this LogConfiguration logConfiguration,
	string configurationFileName = null,
	string sectionName = "FileLogging"
)

Parameters

logConfiguration  LogConfiguration
日誌配置物件
configurationFileName  String  (Optional)
設定檔名稱 (可選,預設: appsettings.json)
sectionName  String  (Optional)
設定區段名稱 (可選,預設: FileLogging)

Return Value

LogConfiguration
LogConfiguration 物件 (支援鏈式呼叫)

Usage Note

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).

Remarks

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" } }

Example

C#
// 使用預設設定檔和預設區段名稱
LogHelper.Configure(config => 
{
    config.UseFileLoggingFromAppSettings();
});

// 指定自訂設定檔和區段名稱
LogHelper.Configure(config => 
{
    config.UseFileLoggingFromAppSettings("myconfig.json", "Logging:File");
});

Revision History

DateVersionDescription
2025/12/1625.0.3.0新增從 appsettings 載入檔案日誌設定功能

See Also