I am using Serilog.Sinks.Email in a console application written in C#. It is "restrictedToMinimumLevel" = "Warning", and I have Warning and Error messages sprinkled throughout the program.
When I ran this application yesterday, I received one email at the end of the run (when control reached Log.CloseAndFlush()) and this email had the consolidated warnings and errors generated during the run.
This is the desired functionality and I was delighted that I did not need to write a wrapper class that would implement it.
When I ran the same script today I received one email for every Error that was encountered.
I am puzzled by this erratic behavior. An extract from my App.config file is reproduced below:
<add key="serilog:using:Email" value="Serilog.Sinks.Email" />
<add key="serilog:write-to:Email.fromEmail" value="<email address>" />
<add key="serilog:write-to:Email.toEmail" value="<email address>" />
<add key="serilog:write-to:Email.mailServer" value="<mail server>" />
<add key="serilog:write-to:Email.mailSubject" value="<application name> [{MachineName}] [User: {UserName}]" />
<add key="serilog:write-to:Email.outputTemplate" value="{Timestamp:yyyy-MM-dd HH:mm:ss}:: [{Level:u3}] {Message}{NewLine}" />
<add key="serilog:write-to:Email.restrictedToMinimumLevel" value="Warning" />
Is there any configuration setting that I should use in order to ensure that the script consistently sends at most one email (with the consolidated warnings and errors) at the end of any run?
Could anyone please point me to documentation that could help in this regard?
I solved this issue by writing a wrapper class.