Esempio n. 1
0
        private Serilog.LoggerConfiguration Configure(LoggerConfiguration settings, EmailSettings emailSettings)
        {
            FolderManager.CheckAndCreateDirectory($@"{_path}\logs");

            var seriLogConfig = new Serilog.LoggerConfiguration()
                                .Enrich
                                .WithExceptionDetails();

            if (settings.EnableSerilogDebugger)
            {
                var file = File.CreateText($@"{_path}\logs\serilog.txt");
                Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
            }

            if (settings.EnableFile)
            {
                seriLogConfig.WriteTo.RollingFile($@"{_path}\logs\log-{{Date}}.txt");
            }

            if (settings.EnableEmail && emailSettings != null && !string.IsNullOrEmpty(settings.LoggingFromEmail) && !string.IsNullOrEmpty(settings.LoggingToEmail))
            {
                seriLogConfig.WriteTo.Email(fromEmail:         settings.LoggingFromEmail,
                                            toEmail:           settings.LoggingToEmail,
                                            mailServer:        emailSettings.Server,
                                            networkCredential: new NetworkCredential
                {
                    Domain   = emailSettings.Domain,
                    UserName = emailSettings.Username,
                    Password = emailSettings.Password
                },
                                            restrictedToMinimumLevel: LogEventLevel.Error);
            }

            return(seriLogConfig);
        }