コード例 #1
0
 /// <inheritdoc />
 protected override void SendBuffer(LoggingEvent[] events)
 {
     if ((events == null) || (serviceChannelFactory == null) || 
         string.IsNullOrEmpty(ApplicationName))
         return;
     using (var tsc = new TransactionScope(TransactionScopeOption.Suppress))
     {
         var currentService = GetLogService();
         var serviceEvents = events.Select(e => Map(e)).ToArray();
         currentService.Handle(serviceEvents);
     }
 }
コード例 #2
0
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            if (loggingEvents == null || loggingEvents.Length < 1)
                return;

            loggingEvents = (from e in loggingEvents where e != null select e).ToArray();
            if (loggingEvents == null || loggingEvents.Length < 1)
                return;

            MongoCollection collection = MongoDbRef.Instance.GetCollection(this);
            BsonDocument[] docs = loggingEvents.Select(BuildBsonDocument).ToArray();
            collection.InsertBatch(docs, WriteConcern.Unacknowledged);
        }
コード例 #3
0
 protected override void Append(LoggingEvent[] loggingEvents)
 {
     var collection = GetCollection(CollectionName);
     IMongoCollection<BsonDocument> dualCollection = null;
     if (!string.IsNullOrWhiteSpace(DualCollectionName))
     {
         dualCollection = GetCollection(DualCollectionName);
     }
     Task.Run(() =>
     {
         collection.InsertManyAsync(loggingEvents.Select(BuildBsonDocument));
         dualCollection?.InsertManyAsync(
             loggingEvents.Where(log => log.Level >= DualCollectionLevelThreshold).Select(BuildBsonDocument));
     });
 }
コード例 #4
0
 protected override void Append(LoggingEvent[] loggingEvents)
 {
     var collection = GetCollection();
     collection.InsertBatch(loggingEvents.Select(BuildBsonDocument));
 }
コード例 #5
0
 protected override void Append(LoggingEvent[] loggingEvents)
 {
     var collection = GetCollection();
     Task.Run(() => collection.InsertManyAsync(loggingEvents.Select(BuildBsonDocument)));
 }
コード例 #6
0
 protected override void Append(LoggingEvent[] loggingEvents)
 {
     var collection = GetCollection();
     collection.InsertManyAsync(loggingEvents.Select(BuildBsonDocument));
     CreateExpiryAfterIndex(collection);
 }
コード例 #7
0
ファイル: MongoDBAppender.cs プロジェクト: rainchan/weitao
 /// <summary>
 /// 将loggingEvent对象转换成Bson对象存入Mongo
 /// </summary>
 /// <param name="loggingEvent">
 /// loggingEvent对象
 /// </param>
 protected override void Append(LoggingEvent[] loggingEvents)
 {
     MongoServer mongo = null;
     try
     {
         mongo = GetMongo();
         mongo.Connect();
         MongoDatabase database = mongo.GetDatabase(DatabaseName ?? "logsDotNet");
         MongoCollection collection = database.GetCollection(CollectionName);
         collection.InsertBatch(loggingEvents.Select(BuildBsonDocument));
     }
     catch (Exception ex)
     {
         WriteLog(string.Format("写入MonogoDb异常,ex={0}", ex.ToString()));
     }
     finally
     {
         if (mongo != null)
         {
             mongo.Disconnect();
         }
     }
 }
コード例 #8
0
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            var mongoDbHelper = new MongoDbHelper();

            // get connectionString from config file
            var connectionString = mongoDbHelper.GetConnectionString(ConnectionStringName, ConnectionString);

            // get database
            var db = mongoDbHelper.GetDatabase(connectionString);

            // get collection
            var collection = mongoDbHelper.GetCollection(
                db,
                CappedCollection != null && Convert.ToBoolean(CappedCollection),
                CollectionName,
                CappedCollectionSize != null ? long.Parse(CappedCollectionSize) : MongoDbHelper.DefaultCappedCollectionSize,
                MaxNumberOfDocuments != null ? long.Parse(MaxNumberOfDocuments) : MongoDbHelper.DefaultCappedCollectionMaxDocuments);

            // build Bson documents
            var bsonDocuments = loggingEvents.Select(loggingEvent => mongoDbHelper.BuildBsonDocument(loggingEvent, _fields)).ToList();

            // insert docs in db
            mongoDbHelper.InsertDocumentsInCollection(bsonDocuments, collection);
        }