serilog / serilog-sinks-email

A Serilog sink that writes events to SMTP email
Apache License 2.0
70 stars 68 forks source link

Using custom text formatter screws mail subject #71

Closed arvigeus closed 6 months ago

arvigeus commented 4 years ago

Version: 2.3.0

var logger = new LoggerConfiguration()
logger .Enrich.FromLogContext();
logger.WriteTo.Email(new EmailConnectionInfo()
{
    EmailSubject = $"DotNet Core Web Dump For {mspName}", // <-- Does not work with textFormatter
    FromEmail = "api@shopmetrics.com",
    IsBodyHtml = true,
    MailServer = "10.10.110.32",
    ToEmail = "nstoynov@shopmetrics.com"
},
    textFormatter: new HtmlFormatter(), // <-- Using this makes EmailSubject to be default subject
    restrictedToMinimumLevel: LogEventLevel.Error);

HtmlFormatter is a custom formatter. Could not find any way to set subject from there.

ddementyev commented 4 years ago

Hi, in this case it is necessary to use the email subject not in the EmailConnectionInfo but after the text formatter like this: subject: "your subject":

textFormatter: new HtmlFormatter(), mailSubject: "subject", // <-- This will work restrictedToMinimumLevel: LogEventLevel.Error);

nblumhardt commented 6 months ago

Closing as stale; 3.0.0-dev makes some improvements to the configuration options around this.