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

CustomFormatter examples?

Open Schoof-T opened this issue 3 years ago • 2 comments

Does this issue relate to a new feature or an existing bug?

  • [x] Question

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.

  • [x] 8.4.1

What is the target framework and operating system? See target frameworks & net standard matrix.

  • [x] netCore 3.1

Please describe the current behavior?

 {
        "Name": "Elasticsearch",
        "Args": {
          "nodeUris": "http://servername:9200",
          "indexFormat": "custom-index-{0:yyyy.MM}",
          "autoRegisterTemplate": true,
          "autoRegisterTemplateVersion": "ESv7"
        }
      }

image

Please describe the expected behavior?

I would like to be able to log more information (Such as the name of the controller, the application name, the server name...) With a file sink we can specify these "outputTemplate": "{Timestamp:yyyyMMdd HH:mm:ss,fff}|{Level}|{SourceContext}|{Message:lj}{NewLine}{Exception}", I saw that there are CustomFormatters, but I can not find any example on how to use these. Are there any examples available? Do the CustomFormatters only adjust the result you can place in "messageTemplate" field, or can you add more fields?

My apologies if this has been asked / answered before but I cannot find it.

Schoof

Schoof-T avatar Nov 20 '20 15:11 Schoof-T

Any property available in the logevent will be saved in Elasticsearch, so make sure to add those to your log message. There are multiple ways, have a look here: https://nblumhardt.com/2016/08/context-and-correlation-structured-logging-concepts-in-net-5/

mivano avatar Nov 20 '20 15:11 mivano

I tried adding an Environment Enricher to SeriLog. And adding "WithMachineName". But this did not get logged to my Elastic Instance. Are the SeriLog enrichers not automatically added?

Schoof-T avatar Nov 20 '20 16:11 Schoof-T