LogConfigurationExtensionsUseElasticSearch(LogConfiguration, ElasticSearchConfiguration, LogLevel) Method
使用 ElasticSearch 作為日誌目標 (完整配置)
// 使用 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
});
});