コード例 #1
0
        /// <summary>
        /// Set the MongoDB logger options based on the key/value application configuration properties.
        /// </summary>
        /// <param name="configuration">Represents a set of key/value application configuration properties. See <see cref="IConfiguration"/>.</param>
        public override void ReadFromConfiguration(IConfiguration configuration)
        {
            var mongoConfiguration = configuration?.GetSection("XLogger:MongoDB");

            if (mongoConfiguration == null)
            {
                throw new System.Exception("Could not load the adapter configuration properties. Make sure the application settings have the XLogger:MongoDB section.");
            }

            var logLevel = mongoConfiguration[nameof(LogLevel)];

            if (!string.IsNullOrEmpty(logLevel))
            {
                LogLevel = (LogLevel)int.Parse(logLevel);
            }
            OnDemand = bool.Parse(mongoConfiguration[nameof(OnDemand)] ?? OnDemand.ToString());

            DatabaseUrl    = mongoConfiguration[nameof(DatabaseUrl)] ?? DatabaseUrl;
            CollectionName = mongoConfiguration[nameof(CollectionName)] ?? CollectionName;
            Capped         = bool.Parse(mongoConfiguration[nameof(Capped)] ?? Capped.ToString());
            MaxSize        = long.Parse(mongoConfiguration[nameof(MaxSize)] ?? MaxSize.ToString());
            MaxDocuments   = long.Parse(mongoConfiguration[nameof(MaxDocuments)] ?? MaxDocuments.ToString());
        }