Ejemplo n.º 1
0
        public static void InitStatic(string[] args)
        {
            args = args ?? Array.Empty <string>();

            //DapperNodaTimeSetup.Register();
            NodeTimeConverter.Register();
            ServicePointManager.UseNagleAlgorithm = true;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.CheckCertificateRevocationList = true;
            ServicePointManager.DefaultConnectionLimit         = 250;
            ServicePointManager.EnableDnsRoundRobin            = true;
            ServicePointManager.DnsRefreshTimeout = 4 * 60 * 1000;

            var cfg = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                      .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true)
                      .AddEnvironmentVariables()
                      .AddCommandLine(args)
                      .Build()
            ;

            var ns = "WebApplicationDemo";

            NLogConfigurer.For(ns)
            .WithArkDefaultTargetsAndRules(ns.Replace('.', '_'), cfg.GetConnectionString("NLog.Database")
                                           , "*****@*****.**", cfg["NLog:NotificationList"]
                                           , cfg.GetConnectionString("NLog.Smtp"))
            .Apply();
        }
Ejemplo n.º 2
0
        public static Host ConfigureFromAppSettings(SkyScanner_Recipe?recipe = null, Action <SkyScanner_Host_Config> configurationOverrider = null)
        {
            try
            {
                var localRecipe = ConfigurationManager.AppSettings[SkyScannerConstants.ConfigKeys.SkyScannerRecipe];
                var mailingList = ConfigurationManager.AppSettings[SkyScannerConstants.ConfigKeys.NLogMailingList];

                SkyScanner_Recipe r = SkyScanner_Recipe.SkyScanner;


                if (recipe.HasValue ||
                    Enum.TryParse <SkyScanner_Recipe>(localRecipe, out r))
                {
                    if (recipe.HasValue)
                    {
                        r = recipe.Value;
                    }

                    NLogConfigurer.For(SkyScannerConstants.AppName)
                    .WithDefaultTargetsAndRulesFromAppSettings($"Logs_{r}", "SkyScanner_Worker", mailingList)
                    .Apply();

                    Host h = null;

                    switch (recipe.GetValueOrDefault(r))
                    {
                    case SkyScanner_Recipe.SkyScanner:
                    {
                        h = _configureForSKYSCANNERFromAppSettings(configurationOverrider);

                        break;
                    }

                    default:
                        throw new NotSupportedException($"not supported recipe {recipe}");
                    }

                    return(h);
                }

                throw new InvalidOperationException("invalid recipe");
            }
            catch (Exception e)
            {
                _logger.Fatal(e, "Failed to configure");
                throw;
            }
        }
Ejemplo n.º 3
0
        public static Host Configure(IConfiguration configuration, Test_Recipe?recipe = null, Action <ITest_Host_Config> configurer = null)
        {
            var mailingList          = configuration["NLog:MailingList"];
            var nlogConnectionString = configuration["ConnectionStrings:NLog.Database"];
            var nlogSmtp             = configuration["ConnectionStrings:NLog.Smtp"];
            var localRecipe          = configuration["Test:Recipe"];

            var ns = Test_Constants.AppName;

            Test_Recipe r = default(Test_Recipe);

            if (recipe.HasValue || Enum.TryParse <Test_Recipe>(localRecipe, out r))
            {
                if (recipe.HasValue)
                {
                    r = recipe.Value;
                }

                NLogConfigurer
                .For(ns)
                .WithDefaultTargetsAndRules(logTableName: $"{r}_{ns.Replace(".", "")}", nlogConnectionString, NLogConfigurer.MailFromDefault, mailingList, nlogSmtp)
                .Apply();

                Host h = null;

                switch (r)
                {
                case Test_Recipe.Test:
                    h = _configureForTest(configuration, configurer);
                    break;

                default:
                    throw new NotSupportedException($"Recipe not supported: {recipe}");
                }

                return(h);
            }

            throw new InvalidOperationException("Invalid Recipe");
        }