Duplicate logs are coming in email?
Closed this issue · 1 comments
smartaquarius10 commented
Team,
I have a global exception middleware in my .net core project. Now, in every mail I'm reciving duplicate logs. One with unhandled exception and other through middleware like this
Reason: | An unhandled exception has occurred while executing the request.
Reason: | "GlobalExceptionMiddleware::Gateway Error Code::1837331373"
Logging Code looks like this
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(Constants.Instance.levelSwitch)
.ReadFrom.Configuration(configuration, "Serilog").CreateLogger();
}
public void ConfigureServices(IServiceCollection services)
{
#region Logging
services.AddLogging(loggingBuilder =>
{
loggingBuilder.ClearProviders();
loggingBuilder.AddSerilog(dispose: true);
});
#endregion
}
Appsettings:- >
"Serilog": {
"Using": [ "Serilog.Sinks.Email", "Serilog.Sinks.File", "Serilog.Sinks.Async" ],
"WriteTo": [
{
"Name": "Email",
"Args": {
"connectionInfo": {
"FromEmail": "xxxxxx",
"ToEmail": "xxaaaaaaa",
"MailServer": "qqqqqqqq",
"Port": 12,
"EmailSubject": "tttttttt",
"IsBodyHtml": true
},
"restrictedToMinimumLevel": "Error",
"outputTemplate": "<table></table>"
}
}
internal Action<ILogger, string, Exception> exceptionLogging;
public readonly LoggingLevelSwitch levelSwitch = new LoggingLevelSwitch();
private LoggerConstants()
{
exceptionLogging= LoggerMessage.Define<string>(
LogLevel.Error,
eventId: 5,
"{Exception}");
}
I call this action delegate to log my message.
Any suggestions please?
nblumhardt commented
Hi! Thanks for your message. This one would be a good fit for the serilog
tag on Stack Overflow (only minimal maintainer time available here). Closing as stale, sorry about the lack of response earlier on.