private void AddToBatch(LogEventInfo logEventInfo, HttpEventCollectorEventInfoBatch batch)
        {
            // Sanity check for LogEventInfo
            if (logEventInfo == null)
            {
                throw new ArgumentNullException(nameof(logEventInfo));
            }

            // Make sure we have a properly setup HttpEventCollectorSender
            if (_hecSender == null)
            {
                throw new NLogRuntimeException("SplunkHttpEventCollector SendEventToServer() called before InitializeTarget()");
            }

            // Build MetaData
            var index = RenderLogEvent(Index, logEventInfo);
            var source = RenderLogEvent(Source, logEventInfo);
            var sourceType = RenderLogEvent(SourceType, logEventInfo);
            var metaData = GetMetaData(index, source, sourceType);

            // Use NLog's built in tooling to get properties
            var properties = GetAllProperties(logEventInfo);

            if (IncludePositionalParameters && logEventInfo.Parameters != null)
            {
                for (var i = 0; i < logEventInfo.Parameters.Length; ++i)
                {
                    properties[string.Concat("{", i.ToString(), "}")] = logEventInfo.Parameters[i];
                }
            }

            // Send the event to splunk
            string renderedMessage = RenderLogEvent(Layout, logEventInfo);
            batch.AddEvent(logEventInfo.TimeStamp, null, logEventInfo.Level.Name, logEventInfo.Message, renderedMessage, logEventInfo.Exception, properties, metaData);
        }
 protected override Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken cancellationToken)
 {
     using (HttpEventCollectorEventInfoBatch batch = _hecSender.StartBatch())
     {
         AddToBatch(logEvent, batch);
         return batch.Send(cancellationToken);
     }
 }
        protected override Task WriteAsyncTask(IList<LogEventInfo> logEvents, CancellationToken cancellationToken)
        {
            using (HttpEventCollectorEventInfoBatch batch = _hecSender.StartBatch())
            {
                foreach (LogEventInfo logEvent in logEvents)
                {
                    AddToBatch(logEvent, batch);
                    cancellationToken.ThrowIfCancellationRequested();
                }

                return batch.Send(cancellationToken);
            }
        }