コード例 #1
0
        public ArangoXmlRepository(IServiceProvider services, ILoggerFactory loggerFactory,
                                   string database, string collection, ArangoContext context)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _logger     = loggerFactory.CreateLogger <ArangoXmlRepository>();
            _services   = services ?? throw new ArgumentNullException(nameof(services));
            _database   = database;
            _collection = collection;
            _context    = context ?? services.GetRequiredService <ArangoContext>();

            try
            {
                if (!_context.ExistDatabaseAsync(_database).Result)
                {
                    _context.CreateDatabaseAsync(_database).Wait();
                }

                var collections = _context.ListCollectionsAsync(_database).Result;

                if (!collections.Contains(collection))
                {
                    _context.CreateCollectionAsync(_database, _collection, ArangoCollectionType.Document).Wait();
                }
            }
            catch (Exception e)
            {
                var logger = _logger;
                logger?.LogError(e, e.Message);
            }
        }
コード例 #2
0
        public ArangoSerilogSink(
            ArangoContext arango,
            string database       = "logs",
            string collection     = "logs",
            int batchPostingLimit = DefaultBatchPostingLimit,
            TimeSpan?period       = null)
            : base(batchPostingLimit, period ?? DefaultPeriod)
        {
            _arango     = arango;
            _database   = database;
            _collection = collection;

            try
            {
                if (!_arango.ExistDatabaseAsync(_database).Result)
                {
                    _arango.CreateDatabaseAsync(_database).Wait();
                }

                var collections = _arango.ListCollectionsAsync(_database).Result;

                if (!collections.Contains(collection))
                {
                    _arango.CreateCollectionAsync(_database, _collection, ArangoCollectionType.Document).Wait();
                }
            }
            catch (Exception)
            {
                //
            }
        }