public void should_load_configuration() { var appenderAConfig = new DefaultAppenderConfig { PrefixPattern = "[%level] @ %time - %logger: " }; var appenderBConfig = new DateAndSizeRollingFileAppenderConfig { FilePathRoot = "totopath " }; var appenderA = new AppenderDefinition { Name = "A", AppenderTypeName = nameof(ConsoleAppender), AppenderJsonConfig = appenderAConfig }; var appenderB = new AppenderDefinition { Name = "B", AppenderTypeName = nameof(DateAndSizeRollingFileAppender), AppenderJsonConfig = appenderBConfig }; var config = new ZeroLogJsonConfiguration { LogEventBufferSize = 5, LogEventQueueSize = 7, RootLogger = new LoggerDefinition { Level = Level.Warn, LogEventPoolExhaustionStrategy = LogEventPoolExhaustionStrategy.DropLogMessage, AppenderReferences = new[] { "A" }, }, Appenders = new[] { appenderA, appenderB }, Loggers = new[] { new LoggerDefinition { Name = "Abc.Zebus", Level = Level.Debug, AppenderReferences = new[] { "B" } } } }; var configJson = JsonConvert.SerializeObject(config); var loadedConfig = JsonConfigurator.DeserializeConfiguration(configJson); Check.That(loadedConfig.LogEventBufferSize).Equals(config.LogEventBufferSize); Check.That(loadedConfig.LogEventQueueSize).Equals(config.LogEventQueueSize); Check.That(loadedConfig.RootLogger.Level).Equals(config.RootLogger.Level); Check.That(loadedConfig.RootLogger.AppenderReferences.Single()).Equals(config.RootLogger.AppenderReferences.Single()); Check.That(loadedConfig.Appenders.Single(a => a.Name == "A").Name).Equals(appenderA.Name); Check.That(loadedConfig.Appenders.Single(a => a.Name == "A").AppenderTypeName).Equals(appenderA.AppenderTypeName); Check.That(loadedConfig.Appenders.Single(a => a.Name == "B").Name).Equals(appenderB.Name); Check.That(loadedConfig.Appenders.Single(a => a.Name == "B").AppenderTypeName).Equals(appenderB.AppenderTypeName); var appenderALoadedConfig = (DefaultAppenderConfig)AppenderFactory.GetAppenderParameters(loadedConfig.Appenders.Single(a => a.Name == "A"), typeof(DefaultAppenderConfig)); Check.That(appenderALoadedConfig.PrefixPattern).IsEqualTo(appenderAConfig.PrefixPattern); var appenderBLoadedConfig = (DateAndSizeRollingFileAppenderConfig)AppenderFactory.GetAppenderParameters(loadedConfig.Appenders.Single(a => a.Name == "B"), typeof(DateAndSizeRollingFileAppenderConfig)); Check.That(appenderBLoadedConfig.Extension).IsEqualTo(appenderBConfig.Extension); Check.That(appenderBLoadedConfig.PrefixPattern).IsEqualTo(appenderBConfig.PrefixPattern); Check.That(appenderBLoadedConfig.FilePathRoot).IsEqualTo(appenderBConfig.FilePathRoot); Check.That(appenderBLoadedConfig.MaxFileSizeInBytes).IsEqualTo(appenderBConfig.MaxFileSizeInBytes); }
public void Connect() { try { var config = JsonConfigurator.GetConnectionStringFromConfigFile(); Mongo.Initialize(config); } catch (Exception) { throw; } }
public void should_load_configuration() { var appenderA = new AppenderDefinition { Name = "A", AppenderTypeName = nameof(ConsoleAppender), AppenderJsonConfig = JSON.Serialize(new DefaultAppenderConfig { PrefixPattern = "[%level] @ %time - %logger: " }) }; var appenderB = new AppenderDefinition { Name = "B", AppenderTypeName = nameof(DateAndSizeRollingFileAppender), AppenderJsonConfig = JSON.Serialize(new DateAndSizeRollingFileAppenderConfig { FilePathRoot = "totopath " }) }; var config = new ZeroLogConfiguration { LogEventBufferSize = 5, LogEventQueueSize = 7, RootLogger = new LoggerDefinition { Level = Level.Warn, LogEventPoolExhaustionStrategy = LogEventPoolExhaustionStrategy.DropLogMessage, AppenderReferences = new [] { "A" }, }, Appenders = new[] { appenderA, appenderB }, Loggers = new[] { new LoggerDefinition { Name = "Abc.Zebus", Level = Level.Debug, AppenderReferences = new [] { "B" } } } }; var configJson = JSON.Serialize(config, Options.PrettyPrint); var loadedConfig = JsonConfigurator.DeserializeConfiguration(configJson); Check.That(loadedConfig.LogEventBufferSize).Equals(config.LogEventBufferSize); Check.That(loadedConfig.LogEventQueueSize).Equals(config.LogEventQueueSize); Check.That(loadedConfig.RootLogger.Level).Equals(config.RootLogger.Level); Check.That(loadedConfig.RootLogger.AppenderReferences.Single()).Equals(config.RootLogger.AppenderReferences.Single()); Check.That(loadedConfig.Appenders.Single(a => a.Name == "A").Name).Equals(appenderA.Name); Check.That(loadedConfig.Appenders.Single(a => a.Name == "A").AppenderTypeName).Equals(appenderA.AppenderTypeName); Check.That(loadedConfig.Appenders.Single(a => a.Name == "A").AppenderJsonConfig).Equals(appenderA.AppenderJsonConfig); Check.That(loadedConfig.Appenders.Single(a => a.Name == "B").Name).Equals(appenderB.Name); Check.That(loadedConfig.Appenders.Single(a => a.Name == "B").AppenderTypeName).Equals(appenderB.AppenderTypeName); Check.That(loadedConfig.Appenders.Single(a => a.Name == "B").AppenderJsonConfig).Equals(appenderB.AppenderJsonConfig); }
public void should_handle_missing_part() { var configJson = @"{ ""RootLogger"": { ""AppenderReferences"": [ ""A"" ], ""Level"": ""Warn"" }, ""Appenders"": [ { ""Name"": ""A"", ""AppenderTypeName"": ""ConsoleAppender"" }, { ""Name"": ""B"", ""AppenderTypeName"": ""DateAndSizeRollingFileAppender"", ""AppenderJsonConfig"": {""FilePathRoot"":""totopath ""} } ], ""Loggers"": [{ ""Name"": ""Abc.Zebus"", ""AppenderReferences"": [ ""B"" ], ""Level"": ""Debug"", ""LogEventPoolExhaustionStrategy"": ""DropLogMessageAndNotifyAppenders"" }] }"; var config = JsonConfigurator.DeserializeConfiguration(configJson); Check.That(config.RootLogger.LogEventPoolExhaustionStrategy).Equals(LogEventPoolExhaustionStrategy.Default); Check.That(config.LogEventBufferSize).Equals(new ZeroLogJsonConfiguration().LogEventBufferSize); Check.That(config.LogEventQueueSize).Equals(new ZeroLogJsonConfiguration().LogEventQueueSize); var appenderConfig = (DateAndSizeRollingFileAppenderConfig)AppenderFactory.GetAppenderParameters(config.Appenders[1], typeof(DateAndSizeRollingFileAppenderConfig)); Check.That(appenderConfig.FilePathRoot).IsEqualTo("totopath "); }
public void ConfigureServices(IServiceCollection services) { services .AddOptions(); services .AddBigBankOlapServices(new Uri(_configuration["DruidBrokerUrl"])); services .AddSingleton(sp => new BigBankDataSourceHealthChecker( new Uri(_configuration["DruidCoordinatorUrl"]), sp.GetRequiredService <ILoggerFactory>())); services .AddSwagger(_hostingEnvironment); services .AddMvc(c => c.Filters.Add <ValidationFilterAttribute>()) .AddJsonOptions(c => JsonConfigurator.ApplySerializerSettings(c.SerializerSettings)); }
static void Main(string[] args) { var configurator = new JsonConfigurator(); var result = configurator.LoadConfiguration <EncryptionConfiguration>(ConfigurationKeys.Encryption); var arguments = configurator.LoadConfiguration <DownloadArguments>(ConfigurationKeys.DownloadArguments); // This little stunt is done so that Encryption will load this correctly Config.Global.Add(ConfigurationKeys.Encryption, result); var ftpService = new FtpService(); var operation = ftpService.GetDownloadOperation(arguments.UserName, arguments.EncryptedPassword.Decrypt(), arguments.HostName, arguments.FtpPath, arguments.DestinationPath, TransferCallback); operation.StartDownload(); //ftpDownload.Password = arguments.EncryptedPassword; // Password = password, // HostName = hostName, }
public async Task CreateDownloader() { var encryption = Config.Global.Get <EncryptionConfiguration>(); var downloadConfiguration = Config.Global.Get <DownloadApplication>(); var jsonConfigurator = new JsonConfigurator(); var destinationPath = Path.Combine("c:\\", "Temp", FolderName); await FileCopier.CopyFromOneFolderToAnother(downloadConfiguration.Location, destinationPath, true); jsonConfigurator.SaveConfiguration(ConfigurationKeys.Encryption, encryption, destinationPath); var downloadArguments = new DownloadArguments { DestinationPath = "Extracted", EncryptedPassword = EncryptedPassword, FtpPath = FtpPath, HostName = HostName, UserName = UserName }; jsonConfigurator.SaveConfiguration(ConfigurationKeys.DownloadArguments, downloadArguments, destinationPath); }
public App() { Mongo.Initialize(JsonConfigurator.GetConnectionStringFromConfigFile("config/db.json")); }