簡體   English   中英

如何使用NLog登錄到Amazon ElasticSearch?

[英]How can I log to Amazon ElasticSearch with NLog?

我正在嘗試使NLog與Amazon ElasticSearch一起使用。

這是我現在得到的:

// Step 1. Create configuration object 
var config = new LoggingConfiguration();

// Step 2. Create targets and add them to the configuration 
var awsTaget = new ElasticSearchTarget();
config.AddTarget("aws", awsTaget);

// Step 3. Set target properties 
awsTaget.Uri = "https://amazonendpoint.com";
awsTaget.Index = "myindex" + DateTime.Now.ToString("yyyy-MM-dd");
awsTaget.DocumentType = "logevent";
awsTaget.Layout = "${message}";

// Step 4. Define rules
var rule3 = new LoggingRule("*", LogLevel.Debug, awsTaget);
config.LoggingRules.Add(rule3);    

// Step 5. Activate the configuration
LogManager.Configuration = config;

// log
var _logger = LogManager.GetLogger("Example");
logger.Debug("debug log message");

我正在使用NLog和NLog.Targets.ElasticSearch。 那是正確的包裹嗎?

由於以下錯誤,您需要在ElasticSearchTarget周圍放置包裝器:

https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/issues/53

var awsTaget = new ElasticSearchTarget();
var awsTargetAsync = new AsyncTargetWrapper(awsTaget) { OverflowAction=AsyncTargetWrapperOverflowAction.Block, BatchSize=10, TimeToSleepBetweenBatches = 0 };

// Step 4. Define rules
var rule3 = new LoggingRule("*", LogLevel.Debug, awsTargetAsync);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM