private static void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.Configure <StackGamerOption>(configuration.GetSection("StackGamerOption")); var stackGamerOption = new StackGamerOption(); configuration.Bind("StackGamerOption", stackGamerOption); var loggingOption = new LoggingOption(); configuration.Bind("Logging", loggingOption); services .AddLogging(logBuilder => { logBuilder.ClearProviders(); logBuilder.SetMinimumLevel(loggingOption.LogLevel); logBuilder.AddNLog(configuration); }) .AddMemoryCache() .AddTransient <Thief>() .AddTransient <StackGameContext>() .AddTransient <Scraper>() .AddTransient <ProductService>() .AddSingleton <ParametersService>() .AddHttpClient("stack-gamer", c => { c.BaseAddress = new Uri(stackGamerOption.Urls.BaseUrl); c.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.185 Mobile Safari/537.36"); }); }
public ApiGatewayConfig() { Balancer.Add(new BalancerOption { Enable = false, Host = "localhost:64516", Nodes = new Node[] { new Node { Host = "google.com", Port = 443, Scheme = "https", Enable = true }, new Node { Host = "amazon.com", Port = 443, Scheme = "https", Enable = true } }, Path = "^(.*)$", Policy = "RoundRobin", Port = 64516, Scheme = "http" }); Proxy.Add(new ProxyOption { Enable = false, Host = "localhost:64516", Node = new Node { Host = "google.com", Port = 443, Scheme = "https" }, Path = "^(.*)$", Port = 64516, Scheme = "http" }); Cache = new CacheOption { Enable = false, Duration = 600, MaximumBodySize = 100 * 1024 * 1024, SizeLimit = 64 * 1024 * 1024, UseCaseSensitivePaths = false }; Logging = new LoggingOption { Enable = false }; }
public bool IsOptionEnabled(string optionName) { System.Collections.IEnumerator myEnumerator = options.GetEnumerator(); // for each option while (myEnumerator.MoveNext()) { LoggingOption current = (LoggingOption)(myEnumerator.Current); if (current.name == optionName) { return(current.enabled); } } MessageBox.Show("Option " + optionName + " not found"); return(false); }
/// <summary> /// Method used to configure the logger. /// By default the logger is set to LoggingOption.None /// </summary> /// <param name="logOpt">How (and if) logging should be performed</param> /// <param name="includeStackTrace">Whether to include the stack trace when logging exceptions</param> /// <param name="logFilePath">Where the log file is stored, if LoggingOption.File is chosen</param> public static void Configure(LoggingOption logOpt, bool includeStackTrace, string logFilePath = "") { _logOpt = logOpt; _stackTrace = includeStackTrace; _logFilePath = logFilePath; if (logOpt != LoggingOption.File) { return; } if (string.IsNullOrWhiteSpace(logFilePath)) { _logFilePath = "LOG.txt"; } else if ((Directory.Exists(logFilePath) || File.Exists(logFilePath)) && File.GetAttributes(logFilePath).HasFlag(FileAttributes.Directory)) { _logFilePath = Path.Combine(_logFilePath, "LOG.txt"); } }