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

how to ingore messageTemplate field?

Open li-zheng-hao opened this issue 2 years ago • 0 comments
trafficstars

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

  • [ ] Bug
  • [√] New Feature

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

image

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

  • [√ ] netCore 2.0
  • [ ] netCore 1.0
  • [ ] 4.7
  • [ ] 4.6.x
  • [ ] 4.5.x

Please describe the current behavior?

The log message is output to elasticsearch with the messagetemplate field , my serilog configuration code:

const string OUTPUT_TEMPLATE =
    "[{Level}] {ENV} {Timestamp:yyyy-MM-dd HH:mm:ss.fff} {SourceContext} <{ThreadId}>  {Message:lj}{NewLine}{Exception}";
var config = new LoggerConfiguration()
#if DEBUG
    .MinimumLevel.Debug()
#else
    .MinimumLevel.Information()
#endif
    .Enrich.WithProperty("ENV", env)
    .Enrich.WithMachineName()
    .Enrich.FromLogContext()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
    .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
    .Enrich.WithExceptionDetails()
    .WriteTo.Console(outputTemplate: OUTPUT_TEMPLATE)
    .WriteTo.File("logs/applog_.log"
        , rollingInterval: RollingInterval.Day
        , outputTemplate: OUTPUT_TEMPLATE);
if (String.IsNullOrWhiteSpace(configuration["Other:ELASTICSEARCH_IPADDR"])==false)
    config.WriteTo.Elasticsearch(
        new ElasticsearchSinkOptions(new Uri(configuration["Other:ELASTICSEARCH_IPADDR"]))
            {
                AutoRegisterTemplate = true,
                OverwriteTemplate = true,
                DetectElasticsearchVersion = true,
                AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
                BufferBaseFilename = "logs/buffer",
                BufferLogShippingInterval =TimeSpan.FromSeconds(10) 
            });

var logger = config.CreateLogger();
Log.Logger = logger;
return logger;

the log message on elasticsearch:

{
  "_index": "logstash-2023.02.14",
  "_type": "_doc",
  "_id": "0_a68cab77-eee1-4004-a17b-70c36d17814b",
  "_version": 1,
  "_score": null,
  "_source": {
    "@timestamp": "2023-02-14T17:10:49.8296587+08:00",
    "level": "Information",
    "messageTemplate": "TEST MESSAGE",
    "message": "TEST MESSAGE",
    "fields": {
      "SourceContext": "FB.Webapi.BackgroundService.MetricsService",
      "ENV": "Testing",
      "MachineName": "WIN-EPISTFOBD41"
    }
  },
  "fields": {
    "@timestamp": [
      "2023-02-14T09:10:49.829Z"
    ]
  },
  "sort": [
    1676365849829
  ]
}

For me, the messageTemplate field is useless, and it will take up a lot of hard disk space,is there anyway to ingore it?

li-zheng-hao avatar Feb 14 '23 09:02 li-zheng-hao