LogConfigurationExtensionsUseElasticSearch(LogConfiguration, ElasticSearchConfiguration, LogLevel) Method

使用 ElasticSearch 作為日誌目標 (完整配置)

Definition

Namespace: eBizprise.Framework.Log.ElasticSearch
Assembly: eBizprise.Framework.Log.LogHelper.ElasticSearch (in eBizprise.Framework.Log.LogHelper.ElasticSearch.dll) Version: 25.0.0.0+adf38c4ccb2bf98d8ad258a6278302b5e05a94ed
C#
public static LogConfiguration UseElasticSearch(
	this LogConfiguration logConfiguration,
	ElasticSearchConfiguration config,
	LogLevel minLevel = null
)

Parameters

logConfiguration  LogConfiguration
日誌配置物件
config  ElasticSearchConfiguration
ElasticSearch 配置選項
minLevel  LogLevel  (Optional)
最小日誌級別 (預設: Trace)

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

Example

C#
// 使用 Basic Authentication
LogHelper.Configure(config => 
{
    config.UseElasticSearch(new ElasticSearchConfiguration
    {
        Uri = "http://localhost:9200",
        IndexFormat = "myapp-${shortdate}",
        Username = "elastic",
        Password = "password",
        IncludeAllProperties = true,
        BatchSize = 100,
        ConnectionTimeout = 30
    });
});

// 使用 ApiKey Authentication
LogHelper.Configure(config => 
{
    config.UseElasticSearch(new ElasticSearchConfiguration
    {
        Uri = "http://localhost:9200",
        IndexFormat = "myapp-${shortdate}",
        ApiKeyId = "VuaCfGcBCdbkQm-e5aOx",
        ApiKey = "ui2lp2axTNmsyakw9tvNnw",
        IncludeAllProperties = true,
        BatchSize = 100,
        ConnectionTimeout = 30
    });
});

See Also