コード例 #1
0
ファイル: MongoTarget.cs プロジェクト: porter1130/NLog.Mongo
        /// <summary>
        /// Writes an array of logging events to the log target. By default it iterates on all
        /// events and passes them to "Write" method. Inheriting classes can use this method to
        /// optimize batch writes.
        /// </summary>
        /// <param name="logEvents">Logging events to be written out.</param>
        protected override void Write(AsyncLogEventInfo[] logEvents)
        {
            if (logEvents.Length == 0)
                return;

            try
            {
                var documents = logEvents.Select(e => CreateDocument(e.LogEvent));

                var collection = GetCollection();
                collection.InsertBatch(documents);

                foreach (var ev in logEvents)
                    ev.Continuation(null);

            }
            catch (Exception ex)
            {
                if (ex is StackOverflowException || ex is ThreadAbortException || ex is OutOfMemoryException || ex is NLogConfigurationException)
                    throw;

                InternalLogger.Error("Error when writing to MongoDB {0}", ex);

                foreach (var ev in logEvents)
                    ev.Continuation(ex);

            }
        }
コード例 #2
0
ファイル: SeqTarget.cs プロジェクト: jasminsehic/seq-client
 /// <summary>
 /// Writes an array of logging events to Seq.
 /// </summary>
 /// <param name="logEvents">Logging events to be written.</param>
 protected override void Write(AsyncLogEventInfo[] logEvents)
 {
     var events = logEvents.Select(e => e.LogEvent);
     PostBatch(events);
 }