public static MongoDBTradeLogger Create(string connectionString, bool enableSSL, string databaseName, string collectionName) { IMongoCollection <BsonDocument> collection = GetOrCreateCollection(connectionString, enableSSL, databaseName, collectionName); var logger = new MongoDBTradeLogger() { collection = collection, connectionString = connectionString, enableSSL = enableSSL, databaseName = databaseName, collectionName = collectionName }; return(logger); }
/// <summary> /// Init setups in any configuration values /// </summary> private void Init() { ConfigurationPackage configPackage = this.Context.CodePackageActivationContext.GetConfigurationPackageObject("Config"); String connectionString = configPackage.Settings.Sections["DB"].Parameters["MongoConnectionString"].Value; bool.TryParse(configPackage.Settings.Sections["DB"].Parameters["MongoEnableSSL"].Value, out var enableSsl); try { tradeLogger = MongoDBTradeLogger.Create(connectionString, enableSsl, databaseName, collectionName); } catch (Exception ex) { ServiceEventSource.Current.ServiceMessage(this.Context, $"Error initializing connection to logger ${ex.Message}"); BackOff(CancellationToken.None).GetAwaiter().GetResult(); Init(); } }