Kabali
Kabali

Reputation: 35

Docker-compose not reading the environment variables to write logs to Elasticsearch

I am setting up docker-compose.yml file to read the environment variables for the docker image. I have serilog.sinks.elasticsearch nuget package referenced in my host project.

If I run the project in Visual Studio with appsettings.json, it reads the settings and sends to logs to Elasticsearch but not through docker-compose.

docker-compose.yml environment specification for docker image:

environment:
      - serilog:MinimumLevel=Verbose
      - serilog:using=Serilog.Sinks.Elasticsearch
      - serilog:WriteTo:Elasticsearch.nodeUris=http://localhost:9200

Local appsettings.json works.

"Serilog": {
        "MinimumLevel": "Debug",
        "WriteTo": [
            {
                "Name": "Elasticsearch",
                "Args": {
                    "nodeUris": "http://localhost:9200"
                }
            }
        ]
    }

MinimumLevel set in docker-compose gets respected.

How to set the docker-compose.yml to read the sink and send the logs to elasticsearch database?

Upvotes: 1

Views: 2221

Answers (2)

Kabali
Kabali

Reputation: 35

following answers worked. shout out to @SKorolchuk.

- serilog:MinimumLevel=Verbose
- Serilog:WriteTo:0:Name=Elasticsearch
- serilog:WriteTo:0:Args:nodeUris=http://localhost:9200

or

Serilog__Using__0=Serilog.Sinks.Elasticsearch
Serilog__WriteTo__0__Name=Elasticsearch
Serilog__WriteTo__0__Args__nodeUris=http://localhost:9200

Upvotes: 2

SK64_DEV
SK64_DEV

Reputation: 326

Try to use double underscore separator, for example - Serilog__MinimumLevel=Verbose. Double underscore is a default separator for Microsoft.Extensions.Configuration.EnvironmentVariables package(If you're not override it in your ConfigurationBuilder composition code). MSDN Environment Variables Configuration Provider reference

Array Environment variable setting is requiring index specification.

Check this:

Serilog__Using__0=Serilog.Sinks.Elasticsearch
Serilog__WriteTo__0__Name=Elasticsearch
Serilog__WriteTo__0__Args__nodeUris=http://localhost:9200

Upvotes: 6

Related Questions