Beispiel #1
0
 public static void Init()
 {
     instance = new TextProvider();
 }
Beispiel #2
0
 /// <summary>
 /// Initializes the global singleton.
 /// </summary>
 public static void Init(Mutation mut)
 {
     instance = new TextProvider(mut);
 }
Beispiel #3
0
        public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            this.env           = env;
            this.loggerFactory = loggerFactory;

            // What am I today? HanDeDict or CHDICT?
            if (Environment.GetEnvironmentVariable("MUTATION") == "CHD")
            {
                mut = Mutation.CHD;
            }
            else if (Environment.GetEnvironmentVariable("MUTATION") == "HDD")
            {
                mut = Mutation.HDD;
            }
            else
            {
                throw new Exception("Environment variable MUTATION missing value invalid. Supported: CHD, HDD.");
            }
            // Now that we know our mutatio, init text provider singleton.
            TextProvider.Init(mut);

            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true)
                          .AddJsonFile("appsettings.devenv.json", optional: true)
                          .AddEnvironmentVariables();
            // Config specific to mutation and hostong environment
            string cfgFileName = null;

            if (env.IsProduction() && mut == Mutation.HDD)
            {
                cfgFileName = "/etc/zdo/zdo-hdd-live/appsettings.json";
            }
            if (env.IsStaging() && mut == Mutation.HDD)
            {
                cfgFileName = "/etc/zdo/zdo-hdd-stage/appsettings.json";
            }
            if (env.IsProduction() && mut == Mutation.CHD)
            {
                cfgFileName = "/etc/zdo/zdo-chd-live/appsettings.json";
            }
            if (env.IsStaging() && mut == Mutation.CHD)
            {
                cfgFileName = "/etc/zdo/zdo-chd-stage/appsettings.json";
            }
            if (cfgFileName != null && File.Exists(cfgFileName))
            {
                builder.AddJsonFile(cfgFileName, optional: false);
            }
            config = builder.Build();

            // If running in production or staging, will log to file. Initialize Serilog here.
            if (!env.IsDevelopment())
            {
                var seriConf = new LoggerConfiguration()
                               .MinimumLevel.Information()
                               .WriteTo.File(config["logFileName"]);
                if (config["logLevel"] == "Trace")
                {
                    seriConf.MinimumLevel.Verbose();
                }
                else if (config["logLevel"] == "Debug")
                {
                    seriConf.MinimumLevel.Debug();
                }
                else if (config["logLevel"] == "Information")
                {
                    seriConf.MinimumLevel.Information();
                }
                else if (config["logLevel"] == "Warning")
                {
                    seriConf.MinimumLevel.Warning();
                }
                else if (config["logLevel"] == "Error")
                {
                    seriConf.MinimumLevel.Error();
                }
                else
                {
                    seriConf.MinimumLevel.Fatal();
                }
                Log.Logger = seriConf.CreateLogger();
            }

            // Log to console (debug) or file (otherwise).
            // Must do here, so log capture errors if singleton services throw at startup.
            LogLevel ll = LogLevel.Critical;

            if (config["logLevel"] == "Trace")
            {
                ll = LogLevel.Trace;
            }
            else if (config["logLevel"] == "Debug")
            {
                ll = LogLevel.Debug;
            }
            else if (config["logLevel"] == "Information")
            {
                ll = LogLevel.Information;
            }
            else if (config["logLevel"] == "Warning")
            {
                ll = LogLevel.Warning;
            }
            else if (config["logLevel"] == "Error")
            {
                ll = LogLevel.Error;
            }
            if (env.IsDevelopment())
            {
                loggerFactory.AddConsole(ll);
            }
            else
            {
                loggerFactory.AddSerilog();
            }
        }