1

Is there a way to configure the Serilog email sink to also include the additional properties in the email body?

I can see the default format is:

{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}

But I am not sure if there is an additional token which can be used or a way in code to easily override this behaviour.

Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123
chrisb
  • 1,395
  • 1
  • 14
  • 35

1 Answers1

0

Update: including {Properties:j} in the output template will now include all of the additional properties.


To include specific additional properties you can pass outputTemplate to the configuration method:

.WriteTo.Email(..., outputTemplate: "Machine: {MachineName}")

There isn't any "wildcard" to output all properties.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • Thanks - the thing is I will not know the names ahead of time. Looking into the source code it looks like I would need to set an alternative ITextFormatter to the default MessageTemplateTextFormatter but as the EmailSink type is not public I cannot do this without editing and rebuilding the Email Sink itself. – chrisb Sep 07 '15 at 14:19
  • I think if the EmailSink type was made public this would be a lot more straight forward. – chrisb Sep 07 '15 at 15:06
  • Will this work even if the properties don't exist for the specific log, for example, if I'm exception handling inside of a LogContext with a specified property and also outside of the LogContext without the property? – Lloyd Powell Feb 20 '17 at 14:24
  • 1
    There is now a "wildcard" by adding {Properties:j} to the output template. See https://github.com/serilog/serilog/wiki/Configuration-Basics#output-templates for more details. – J Man Jun 26 '19 at 17:51