serilog

Does Serilog have a way to limit the overall size of a logEvent?


I have a custom Sink which writes to an Azure Queue Storage, and for some events, especially when destructuring large instances, we are reaching the size limit of the message which Azure has on queued messages (64KB or 48KB for Base64 encoded messages). I get an exception when placing the message on the queue. I need to avoid the exception and truncate the message to fit.

Does Serilog have a built in way to help limit the overall size of a LogEvent, or do we have to code that limiter ourselves?


Solution

  • This needs to be implemented at the sink level because different representations have different size requirements. There is an example of size limiting for JSON in: https://github.com/serilog/serilog-sinks-seq/blob/dev/src/Serilog.Sinks.Seq/Sinks/Seq/SeqSink.cs#L147

    Serilog also has Destructure.ToMaximumDepth(n), but this isn't precise enough for the kind of control you're looking for.