public string ConnectionStringName { get; set; }
///
/// Gets or sets the elasticsearch uri, can be multiple comma separated.
///
public string Uri { get; set; } = "https://xxxxxxxxx:8085";
///
/// Set it to true if ElasticSearch uses BasicAuth
///
public bool RequireAuth { get; set; } = true;
///
/// Username for basic auth
///
public string Username { get; set; } = "admin";
///
/// Password for basic auth
///
public string Password { get; set; } = "admin";
///
/// Set it to true to disable proxy detection
///
public bool DisableAutomaticProxyDetection { get; set; }
///
/// Gets or sets the name of the elasticsearch index to write to.
///
public Layout Index { get; set; } = "logstash-${date:format=yyyy.MM.dd}";
///
/// Gets or sets whether to include all properties of the log event in the document
///
public bool IncludeAllProperties { get; set; }
///
/// Gets or sets a comma separated list of excluded properties when setting
///
public string ExcludedProperties { get; set; }
///
/// Gets or sets the document type for the elasticsearch index.
///
[RequiredParameter]
public Layout DocumentType { get; set; } = "logevent";
///
/// Gets or sets a list of additional fields to add to the elasticsearch document.
///
[ArrayParameter(typeof(Field), "field")]
public IList Fields { get; set; } = new List();
///
/// Gets or sets an alternative serializer for the elasticsearch client to use.
///
public IElasticsearchSerializer ElasticsearchSerializer { get; set; }
///
/// Gets or sets if exceptions will be rethrown.
///
/// Set it to true if ElasticSearchTarget target is used within FallbackGroup target (https://github.com/NLog/NLog/wiki/FallbackGroup-target).
///
public bool ThrowExceptions { get; set; }
protected override void InitializeTarget()
{
base.InitializeTarget();
var uri = ConnectionStringName.GetConnectionString() ?? Uri;
var nodes = uri.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(url => new Uri(url));
var connectionPool = new StaticConnectionPool(nodes);
var config = new ConnectionConfiguration(connectionPool);
if (ElasticsearchSerializer != null)
config = new ConnectionConfiguration(connectionPool, ElasticsearchSerializer);
if (RequireAuth)
config.BasicAuthentication(Username, Password);
if (DisableAutomaticProxyDetection)
config.DisableAutomaticProxyDetection();
_client = new ElasticLowLevelClient(config);
if (!string.IsNullOrEmpty(ExcludedProperties))
_excludedProperties = ExcludedProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
public void FormPayload()
{
try
{
InitializeTarget();
var payload = new List