Formatting HTML Email
Seq can automatically send email when events are logged – this is accomplished using the Email+ app Seq.App.EmailPlus, which you can install directly from NuGet by following the instructions here.
Important Note
The first email app written for Seq is called Seq.App.Email. This is now deprecated, but still published so that users of that version can continue receiving updates and bug fixes. The newer app, described here, is Seq.App.EmailPlus.
The Default Template
Once the app is installed and an instance configured, you're all set to send email: the app comes with a simple template out of the box that turns this event:
Into an HTML email like this:
The template will show the details of the event including its timestamp, level, message and properties.
For development and testing of email templates, we use the excellent Papercut local email server/viewer.
Linking Back to your Seq Server
The email sent by Seq includes a link back to view the event on the Seq server. This uses the address on which Seq is configured to listen - http://localhost:5341 by default.
To set a different hostname, configure your Seq instance to listen at a specific URL.
Writing Handlebars Templates
If you would like to send email with a different body, you can provide an HTML template using Handlebars syntax.
Looking for an example?
The default template itself is published on GitHub for you to read and modify.
To include a property like CartSize
in the email body, simply include it in double-braces:
<p>A new sale was processed for {{CartSize}} items.</p>
Built-in Properties
In addition to the properties from the event payload, a number of built-in properties provide access to the event's metadata. These are prefixed with a dollar sign and include:
Name | Description |
---|---|
$EventType | The type assigned to the event, for example $00COFFEE |
$Exception | The full text of the exception attached to the event, if any, including stack trace |
$Id | The event's id, for example event-1234...abcd |
$Level | Verbose, Debug, Warning, Error, or Fatal |
$LocalTimestamp | The local timestamp attached to the event including timezone offset |
$Instance | The instance name of the Seq server sending the email, if any |
$Message | The rendered message text for the event |
$MessageTemplate | The message template for the event |
$Properties | A list of Name/Value pairs describing the event's properties; see below |
$ServerUrl | The Seq server's listening URL |
$UtcTimestamp | The UTC timestamp of the event |
Enumerating event properties
To list properties attached to the event, use the Handlebars each construct. Property objects have a name and a value; there's a built-in helper called "pretty" that can format complex objects if necessary.
<ul>
{{#each $Properties}}
<li>{{@key}} is {{pretty this}}</li>
{{/each}}
</u>
Updated over 5 years ago