serilog / serilog-sinks-email

A Serilog sink that writes events to SMTP email
Apache License 2.0
70 stars 68 forks source link

[.Net Core application] How to set BatchSizeLimit in appsettings.json #126

Open dailyenergy opened 4 months ago

dailyenergy commented 4 months ago

by browsing through source code and other issues I have figured out that I can add Serilog Mail sink in appsettings as follows:

        "Name": "Email",
        "Args": {
          "From": "test@mail.host",
          "To": "test@mail.host",
          "Host": "localhost",
          "Port": 25,
          "Subject": "[{Level}] Log Email",
          "Body": "{Timestamp:yyyy-MM-dd HH:mm} [{Level}] <{MachineName}> {Message}{NewLine}{Exception}",
          "RestrictedToMinimumLevel": "Warning",

But I have no clue how to set BatchSizeLimit. Do I really need to create a custom extension for LoggerSinkConfiguration?

MrPsi commented 3 months ago

Try this, also see https://github.com/serilog/serilog-sinks-email/issues/130

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information"
    },
    "WriteTo": [
      {
        "Name": "Email",
        "Args": {
          "options": {
            "subject": "Serilog test",
            "from": "from@email.com",
            "to": [ "to@email.com" ],
            "host": "localhost",
            "body": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{Exception}{NewLine}"
          },
          "batchingOptions": {
            "batchSizeLimit": 10,
            "period": "00:00:01"
          },
          "restrictedToMinimumLevel": "Information"
        }
      }
    ]
  }
}