serilog / serilog-sinks-email

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

Duplicate logs are coming in email? #93

Closed smartaquarius10 closed 6 months ago

smartaquarius10 commented 3 years ago

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 6 months ago

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.