/// <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); } }
/// <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); }