Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

how to ingore messageTemplate field? #514

Open
5 tasks
li-zheng-hao opened this issue Feb 14, 2023 · 0 comments
Open
5 tasks

how to ingore messageTemplate field? #514

li-zheng-hao opened this issue Feb 14, 2023 · 0 comments

Comments

@li-zheng-hao
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant