elastic / ecs-dotnet

https://www.elastic.co/guide/en/ecs-logging/dotnet/current/setup.html
Apache License 2.0
108 stars 54 forks source link

Serilog: How to pass header to StaticNodePool or SniffingNodePool #362

Closed dtkujawski closed 5 months ago

dtkujawski commented 5 months ago

When initializing Elastic.Serilog.Sinks when using the CloudNodePool, I can send a header with either U/P or ApiKey. For example:

var header = new Elastic.Transport.BasicAuthentication(config.Username, config.Password);
var pool = new CloudNodePool(config.CloudId, header);
var transportConfig = new TransportConfiguration(pool);
var options = new ElasticsearchSinkOptions(new DefaultHttpTransport(transportConfig));
loggerConfiguration = loggerConfiguration.WriteTo.Elasticsearch(options);

However, if I want to use SniffingNodePool or StaticNodePool I don't see the ability of adding the header to the constructor:

var pool = new SniffingNodePool(config.Urls.Select(x => new Uri(x)).ToArray());

Is there a way to add U/P or ApiKey header when using the NodePool?

dtkujawski commented 5 months ago

Note: I was able to resolve by adding the header after the pool was added to the transportConfig

var header = new Elastic.Transport.BasicAuthentication(config.Username, config.Password);
var pool = new SniffingNodePool(config.Urls.Select(x => new Uri(x)).ToArray());
var transportConfig = new TransportConfiguration(pool);
transportConfig.Authentication(header);