예제 #1
0
        public static Configurer WithArkDefaultTargetsAndRules(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, string smtpConnectionString, bool consoleEnabled = false, bool async = true)
        {
            if (consoleEnabled)
            {
                @this
                .WithConsoleTarget(async)
                .WithConsoleRule("*", LogLevel.Trace);
            }

            if (!string.IsNullOrWhiteSpace(connectionString))
            {
                @this
                .WithDatabaseTarget(logTableName, connectionString, async)
                .WithDatabaseRule("*", LogLevel.Info);
            }

            if (!string.IsNullOrWhiteSpace(smtpConnectionString))
            {
                @this
                .WithMailTarget(mailFrom, mailTo, smtpConnectionString, async: false)
                .WithMailRule("*", LogLevel.Fatal)
                ;
            }

            if (Debugger.IsAttached)
            {
                @this
                .WithDebuggerTarget()
                .WithDebuggerRule()
                ;
            }

            return(@this);
        }
예제 #2
0
 public static Configurer WithMailTargetFromCloudConfiguration(this Configurer @this, string to, bool async = true)
 {
     return(@this.WithMailTarget(
                NLogConfigurer.MailFromDefault
                , to
                , CloudConfigurationManager.GetSetting(NLogDefaultConfigKeys.SmtpServer)
                , int.Parse(CloudConfigurationManager.GetSetting(NLogDefaultConfigKeys.SmtpPort))
                , CloudConfigurationManager.GetSetting(NLogDefaultConfigKeys.SmtpUserName)
                , CloudConfigurationManager.GetSetting(NLogDefaultConfigKeys.SmtpPassword)
                , bool.Parse(CloudConfigurationManager.GetSetting(NLogDefaultConfigKeys.SmtpUseSsl))
                ));
 }
 public static Configurer WithMailTargetFromAppSettings(this Configurer @this, string from, string to, bool async = true)
 {
     return(@this.WithMailTarget(
                from
                , to
                , ConfigurationManager.AppSettings[NLogDefaultConfigKeys.SmtpServer]
                , int.Parse(ConfigurationManager.AppSettings[NLogDefaultConfigKeys.SmtpPort])
                , ConfigurationManager.AppSettings[NLogDefaultConfigKeys.SmtpUserName]
                , ConfigurationManager.AppSettings[NLogDefaultConfigKeys.SmtpPassword]
                , bool.Parse(ConfigurationManager.AppSettings[NLogDefaultConfigKeys.SmtpUseSsl])
                ));
 }
예제 #4
0
        public static Configurer WithArkDefaultTargetsAndRules(this Configurer @this, string logTableName, string connectionString, string mailFrom, string mailTo, bool isProduction = true, bool async = true)
        {
            @this.WithConsoleTarget(async);

            if (!isProduction)
            {
                @this.WithConsoleRule("*", LogLevel.Trace);
            }
            else
            {
                @this.WithConsoleRule("*", LogLevel.Warn);
            }

            if (!string.IsNullOrWhiteSpace(connectionString))
            {
                @this
                .WithDatabaseTarget(logTableName, connectionString, async)
                .WithDatabaseRule("*", LogLevel.Info);
            }

            // assume system.mail

            @this
            .WithMailTarget(mailFrom, mailTo, async: false)
            .WithMailRule("*", LogLevel.Fatal)
            ;

            if (Debugger.IsAttached)
            {
                @this
                .WithDebuggerTarget()
                .WithDebuggerRule()
                ;
            }

            return(@this);
        }