Ejemplo n.º 1
0
        public Startup()
        {
            var envName = EnvironmentUtility.GetCurrentEnvironment();

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile($"appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{envName}.json", optional: true, reloadOnChange: true)
                          .AddEnvironmentVariables(Api.ApiBasicConfiguration?.EnvironmentVariablesPrefix);

            Api.ConfigurationRoot = builder.Build();

            Api.ConfigurationRoot.GetSection("ApiSettings").Bind(Api.ApiSettings);
            Api.ConfigurationRoot.GetSection("HealthcheckSettings").Bind(Api.HealthcheckSettings);
            Api.ConfigurationRoot.GetSection("LogSettings").Bind(Api.LogSettings);
            Api.ConfigurationRoot.GetSection("QueueSettings").Bind(Api.QueueSettings);
            Api.ConfigurationRoot.GetSection("DatabaseSettings").Bind(Api.DatabaseSettings);
            Api.ConfigurationRoot.GetSection("DocsSettings").Bind(Api.DocsSettings);
            Api.ConfigurationRoot.GetSection("ShutdownSettings").Bind(Api.ShutdownSettings);
            Api.ConfigurationRoot.GetSection("CacheSettings").Bind(Api.CacheSettings);

            //Create this lógic to keep retrocompatibility because we change the IpRateLimiting section name to RateLimiting
            var ipRateLimitingSection = Api.ConfigurationRoot.GetSection("IpRateLimiting");

            if (ipRateLimitingSection.Exists())
            {
                ipRateLimitingSection.Bind(Api.RateLimitingAdditional);
            }
            else
            {
                Api.ConfigurationRoot.GetSection("RateLimiting").Bind(Api.RateLimitingAdditional);
            }
        }
Ejemplo n.º 2
0
        public static void SetupSerilog(
            this IServiceCollection services,
            string domain,
            string application,
            LoggerSettings settings,
            List <string> ignoredRoutes)
        {
            var loggerBuilder = new LoggerBuilder();

            if (settings?.NewRelicOptions?.Enabled == true && string.IsNullOrWhiteSpace(settings?.NewRelicOptions?.LicenseKey))
            {
                settings.NewRelicOptions.LicenseKey = Environment.GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY");
            }

            Log.Logger = loggerBuilder
                         .UseSuggestedSetting(domain, application)
                         .SetupSeq(settings?.SeqOptions)
                         .SetupSplunk(settings?.SplunkOptions)
                         .SetupNewRelic(settings?.NewRelicOptions)
                         .SetupDataDog(settings?.DataDogOptions)
                         .BuildLogger();

            if (settings?.DebugEnabled ?? false)
            {
                loggerBuilder.EnableDebug();
            }

            var config = new SerilogConfiguration
            {
                Version              = Api.ApiSettings.BuildVersion,
                InformationTitle     = settings?.TitlePrefix + CommunicationLogger.DefaultInformationTitle,
                ErrorTitle           = settings?.TitlePrefix + CommunicationLogger.DefaultErrorTitle,
                BlacklistRequest     = settings?.GetJsonBlacklistRequest(),
                BlacklistResponse    = settings?.JsonBlacklistResponse,
                HeaderBlacklist      = settings?.HeaderBlacklist,
                QueryStringBlacklist = settings?.QueryStringBlacklist,
                RequestKeyProperty   = RequestKeyServiceExtension.RequestKeyHeaderName,
                AccountIdProperty    = AccountIdServiceExtension.AccountIdHeaderName,
                TimeElapsedProperty  = TimeElapsedServiceExtension.TimeElapsedHeaderName,
                IgnoredRoutes        = ignoredRoutes
            };

            StaticSimpleLogger.UpdateVersion(Api.ApiSettings.BuildVersion);
            StaticSimpleLogger.UpdateEnvironment(EnvironmentUtility.GetCurrentEnvironment());

            services.SetupSerilog(config);
            services.AddScoped <ISimpleLogger, SimpleLogger>();
        }
Ejemplo n.º 3
0
        public IActionResult GetAppInfo()
        {
            this.DisableLogging();

            return(Ok(new HomeDetails
            {
                RIP = GracefullShutdownState.RequestsInProgress,
                Service = Api.ApiBasicConfiguration?.ApiName,
                BuildVersion = Api.ApiSettings?.BuildVersion,
                Environment = EnvironmentUtility.GetCurrentEnvironment(),
                RequestKey = RequestKey.Value,
                Application = Api.ApiSettings.Application,
                Domain = Api.ApiSettings.Domain,
                JsonSerializer = Api.ApiSettings.JsonSerializer,
                EnvironmentPrefix = Api.ApiBasicConfiguration.EnvironmentVariablesPrefix,
                TimezoneInfo = new TimezoneInfo(HttpContextAccessor)
            }));
        }
Ejemplo n.º 4
0
        public Startup()
        {
            var envName = EnvironmentUtility.GetCurrentEnvironment();

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile($"appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{envName}.json", optional: true, reloadOnChange: true)
                          .AddEnvironmentVariables(Api.ApiBasicConfiguration?.EnvironmentVariablesPrefix);

            Api.ConfigurationRoot = builder.Build();

            Api.ConfigurationRoot.GetSection("ApiSettings").Bind(Api.ApiSettings);
            Api.ConfigurationRoot.GetSection("HealthcheckSettings").Bind(Api.HealthcheckSettings);
            Api.ConfigurationRoot.GetSection("LogSettings").Bind(Api.LogSettings);
            Api.ConfigurationRoot.GetSection("QueueSettings").Bind(Api.QueueSettings);
            Api.ConfigurationRoot.GetSection("DatabaseSettings").Bind(Api.DatabaseSettings);
            Api.ConfigurationRoot.GetSection("DocsSettings").Bind(Api.DocsSettings);
            Api.ConfigurationRoot.GetSection("ShutdownSettings").Bind(Api.ShutdownSettings);
            Api.ConfigurationRoot.GetSection("IpRateLimiting").Bind(Api.IpRateLimitingAdditional);
            Api.ConfigurationRoot.GetSection("CacheSettings").Bind(Api.CacheSettings);
            Api.ConfigurationRoot.GetSection("WorkerSettings").Bind(Api.WorkerSettings);
        }