serilog-sinks-elasticsearch icon indicating copy to clipboard operation
serilog-sinks-elasticsearch copied to clipboard

configure basic auth from appsettings.json

Open kvanska opened this issue 6 years ago • 5 comments
trafficstars

to set basic auth from code I would use:

var options = new ElasticsearchSinkOptions(new Uri(elasticConnection)) { AutoRegisterTemplate = true, IndexFormat = $"{appSettings.ElasticPreIndex}_log_api-{0:yyyy.MM.dd}", options.ModifyConnectionSettings = (c) => c.BasicAuthentication(appSettings.ElasticBasicAuthUserName, appSettings.ElasticBasicAuthPassword) };

How is this possible to set this from appsettings.json.

Also, I tried to set all the other sinks (console, etc) from appsettings.json and then using both:

Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(config) .WriteTo.Elasticsaerch(options) .CreateLogger()

But only the settings from the .ReadFrom.... are applied.

kvanska avatar Sep 02 '19 18:09 kvanska

I think that as workaround you can pass credentials for http basic auth via your node url. The format is: http(s)://username:[email protected]:XXXX

TdMxm avatar Feb 01 '20 12:02 TdMxm

I think that as workaround you can pass credentials for http basic auth via your node url. The format is: http(s)://username:[email protected]:XXXX

brilliant it works for me

AHashem1 avatar Apr 05 '20 10:04 AHashem1

I think that as workaround you can pass credentials for http basic auth via your node url. The format is: http(s)://username:[email protected]:XXXX

It looks like it works for a single node only, but not for several nodes separated by ; or ,

MikhailSP avatar Jan 18 '21 12:01 MikhailSP

Hi all, I considering about user roles on ELK for Serilog. Which role is enough for logging ?

Thanks !

anhhtca avatar Sep 04 '21 03:09 anhhtca

Elasticsearch has property connectionGlobalHeaders. You can use it by passing base64 encoded username:password pair like this "connectionGlobalHeaders": "Authorization=Basic base64Encode(username:password)",

h-hakobyan avatar Mar 02 '22 14:03 h-hakobyan