using System; using DDNSUpdater.Interfaces; using DDNSUpdater.Logging; using DDNSUpdater.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using RestSharp; static T ParseEnum(string value) { return (T) Enum.Parse(typeof(T), value, true); } var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false); LogLevel loglevel; if (Environment.GetEnvironmentVariables()["LogLevel"] != null) loglevel = ParseEnum(Environment.GetEnvironmentVariables()["LogLevel"].ToString()); else loglevel = LogLevel.Information; var configuration = builder.Build(); /*var logConfig = new OptionsMonitor(); logConfig.CurrentValue.LogLevelToColorMap[LogLevel.Warning] = ConsoleColor.DarkCyan; logConfig.CurrentValue.LogLevelToColorMap[LogLevel.Error] = ConsoleColor.DarkRed;*/ var serviceProvider = new ServiceCollection() .AddSingleton(configuration) .AddLogging(logging => { logging.AddSpecterConsoleLogger(configuration => { // Replace warning value from appsettings.json of "Cyan" configuration.LogLevelToColorMap[LogLevel.Warning] = ConsoleColor.DarkCyan; configuration.LogLevelToColorMap[LogLevel.Debug] = ConsoleColor.Yellow; // Replace warning value from appsettings.json of "Red" configuration.LogLevelToColorMap[LogLevel.Error] = ConsoleColor.DarkRed; }); logging.SetMinimumLevel(loglevel); }) .AddSingleton() .AddSingleton() .BuildServiceProvider(); var dataAccess = serviceProvider.GetService(); dataAccess.Start(); var timerService = serviceProvider.GetService(); timerService.Start(); Console.ReadKey();