serilog-contrib / Serilog.Sinks.Logz.Io

Apache License 2.0
15 stars 11 forks source link

Top level properties, not inside the json properties #26

Closed lukos closed 2 years ago

lukos commented 2 years ago

We have previously used LogzIoDurableHttp for our microservices and it all works well. If we call e.g. .Enrich.WithProperty("AppName", "Microservices.EmailWorker") then in logzio, this appears as a top level property.

image

However, we have some short running pods that should not use buffering because they might not run for long enough to flush the buffer. I followed the advice on the front page and changed the config to use:

"WriteTo": [
      {
        "Name": "LogzIo",
        "Args": {
          "authToken": "token-goes-here",
          "type": "app",
          "dataCenterSubDomain": "listener-uk",
          "useHttps": true,
          "batchPostingLimit": 5000,
          "period": "00:00:02",
          "lowercaseLevel": true,
          "Port": 8071
        }
      }
    ]

But doing this means that when I call .Enrich.WithProperty("AppName", "Microservices.EmailWorker"), this is not added as a top-level property but as a child of "properties" which breaks filtering:

image

Is there something else I can do to make these appear as top-level?

Thanks

mantasaudickas commented 2 years ago

Hey,

yes, you should be able to use boostProperties configuration:

"WriteTo": [
      {
        "Name": "LogzIo",
        "Args": {
          "authToken": "token-goes-here",
          "type": "app",
          "dataCenterSubDomain": "listener-uk",
          "useHttps": true,
          "batchPostingLimit": 5000,
          "period": "00:00:02",
          "lowercaseLevel": true,
          "Port": 8071,
          "boostProperties": true
        }
      }
    ]
lukos commented 2 years ago

Thanks. That works great for the properties although I still don't see all events unless I step through slowly enough to give them time to send (not crazy slow). The pod is checking for a batch of work and if there is none, it will log some messages an exit. Although I don't need all of the log messages in this example, I am worried that if it does pick up work but still finished quickly, I won't see all log messages.

I call Log.CloseAndFlush(); in a finally block. Is there any other way I can make sure the messages are sent before the application exits?

Thanks

lukos commented 2 years ago

Sorry. It does work fine after all. It was because I was calling Log.CloseAndFlush() in a finally but calling Environment.Exit() which basically kills the app without finishing gracefully (this is needed to make the Docker container report the correct code to the Cluster!)

I have refactored to set a return code, call the finally and then call Environment.Exit().