Closed fairking closed 4 years ago
Could be also an ability to look for an InnerException
which also can be ConnectionException
.
Also those different recipients could receive emails in different formats. Eg. the ConnectionException can contain a message only without a stacktrace.
@fairking you can add multiple loggers with different filters.
var emailConnection1 = new EmailConnectionInfo {
...
ToEmail = "service@mail.com"
};
var emailLog1 = new LoggerConfiguration().MinimumLevel.Error()
.Filter.ByIncludingOnly(m=>m.Exception is ConnectionException || m.Exception.InnerException is ConnectionException ... )
.WriteTo.Email(emailConnection1, restrictedToMinimumLevel: LogEventLevel.Error,outputTemplate: "...."
).CreateLogger();
var emailConnection2 = new EmailConnectionInfo {
...
ToEmail = "dev@mail.com"
};
var emailLog2 = new LoggerConfiguration().MinimumLevel.Error()
.Filter.ByExcluding(m=>m.Exception is ConnectionException || m.Exception.InnerException is ConnectionException ... )
.WriteTo.Email(emailConnection2, restrictedToMinimumLevel: LogEventLevel.Error,outputTemplate: "...."
).CreateLogger();
logConfig = logConfig.WriteTo.Logger(emailLog1).WriteTo.Logger(emailLog2);
var log = logConfig.CreateLogger();
I am looking for a logger which can allow me to send different errors to different recipients. For example the
ConnectionException
or any derived exceptions must go to theservice@mail.com
email but any otherException
must be sent to thedevs@mail.com
address. Is it possible with serilog?