Beispiel #1
0
        private BsonDocument BuildBsonDocument(LoggingEvent log)
        {
            if (_fields.Count == 0)
            {
                return(MongoBackwardCompatibility.BuildBsonDocument(log));
            }
            var doc = new BsonDocument();

            foreach (MongoAppenderFileld field in _fields)
            {
                object value     = field.Layout.Format(log);
                var    bsonValue = value as BsonValue ?? BsonValue.Create(value);
                doc.Add(field.Name, bsonValue);
            }

            return(doc);
        }
Beispiel #2
0
        private MongoDatabase GetDatabase()
        {
            string connStr = GetConnectionString();

            if (string.IsNullOrWhiteSpace(connStr))
            {
                return(MongoBackwardCompatibility.GetDatabase(this));
            }

            MongoUrl url = MongoUrl.Create(connStr);

            // TODO Should be replaced with MongoClient, but this will change default for WriteConcern.
            // See http://blog.mongodb.org/post/36666163412/introducing-mongoclient
            // and http://docs.mongodb.org/manual/release-notes/drivers-write-concern
            MongoServer conn = MongoServer.Create(url);
            TimeSpan    ts   = new TimeSpan(0, 0, 0, 0, 500);


            conn.Connect(ts);

            MongoDatabase db = conn.GetDatabase(url.DatabaseName ?? "log4net");

            return(db);
        }