简体   繁体   English

如何使用NLog登录到Amazon ElasticSearch?

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

I am trying to get NLog working with Amazon ElasticSearch. 我正在尝试使NLog与Amazon ElasticSearch一起使用。

This is what I got at the moment: 这是我现在得到的:

// 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");

I am using NLog and NLog.Targets.ElasticSearch. 我正在使用NLog和NLog.Targets.ElasticSearch。 Is that the right packages? 那是正确的包裹吗?

You need to put a wrapper around ElasticSearchTarget because of the following bug: 由于以下错误,您需要在ElasticSearchTarget周围放置包装器:

https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/issues/53 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