elastic / ecs-dotnet

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

How can I set the level of logging from a json file for this library #310

Closed pantonis closed 1 year ago

pantonis commented 1 year ago

I m using Serilog to write to a file and also to push to Elastic (using Elastic.Serilog.Sinks 8.6.0) How can I specify in the json file which log level to append to Elastic?

  "Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console", "Serilog.ElasticSearch" ],

does not seem to work

YoussefWaelMohamedLotfy commented 1 year ago

@pantonis You should be setting the MinimumLevel property in Serilog JSON Config as follows

 "Serilog": {
        // You should add this to set the minimum log level
        "MinimumLevel": {
            "Default": "Information",
            "Override": {
                "Microsoft.AspNetCore": "Warning"
            }
        },
        "WriteTo": [
            {
                "Name": "Console"
            }
            {
                "Name": "Elasticsearch",
                "Args": {
                    "nodeUris": "http://elasticsearch:9200",
                    "indexFormat": "logs-{0:yyyy.MM}",
                    "emitEventFailure": "WriteToSelfLog",
                    "autoRegisterTemplate": true,
                    "registerTemplateFailure": "IndexAnyway",
                    "numberOfShards": 2,
                    "numberOfReplicas": 1
                }
            }
        ]
    }
pantonis commented 1 year ago

@YoussefWaelMohamedLotfy I think the Args you specified are properties of Serilog.Sink.ElasticSearch library not of this library.

Mpdreamz commented 1 year ago

Thanks for bringing this to my attention!

Opened https://github.com/elastic/ecs-dotnet/pull/328 to add the ability to give the sink its own dedicated minimum log level.