1

Using serilog to log a object, e.g. Log.Information("{@log}", log). Where log is a custom object.

The logs comes out like

{
    "@t": "2020-01-24T09:31:23.5064000Z",
    "@mt": "{@log}",
    "log": {
        "TraceId": "e57afecc-8efe-4d48-8057-d46cce71c3d9",
        "Timestamp": "01/24/2020 09:31:23",
        "Service": "serviceType",
        "Action": "actionType",
        "$type": "BaseLog"
    }
}

I'd like not to have the extra serilog properties on there, and just have a flat structure of my log, e.g.

Even when i'm using CompactJsonFormatter

{
        "TraceId": "e57afecc-8efe-4d48-8057-d46cce71c3d9",
        "Timestamp": "01/24/2020 09:31:23",
        "Service": "serviceType",
        "Action": "actionType"
}

Is there an option/extension to serilog where I can remove these?

Jake Owen
  • 137
  • 1
  • 9
  • Try changing the default formatting output string: https://github.com/serilog/serilog/wiki/Formatting-Output – asawyer Jan 24 '20 at 17:16
  • this is pretty much by design, see readme https://github.com/serilog/serilog-formatting-compact - have a scan of the code to see if there's a workaround (also wondering why you dont actually want a message, see https://nblumhardt.com/2016/06/structured-logging-concepts-in-net-series-1/) – Ruben Bartelink Jan 25 '20 at 00:00
  • on reading some more: you may be able to map your log to a LogEvent and/or use techniques like in https://stackoverflow.com/questions/49592351/redirect-all-nlog-output-to-serilog-with-a-custom-target – Ruben Bartelink Jan 25 '20 at 00:02

1 Answers1

-3

Do not put the burden of log transformation on your application, but you can use something like fluentd or logstash to do this for you. They are meant for doing those things.