smashraid / NLog.Splunk

Splunk target to send logs in splunk
0 stars 1 forks source link

Remember to call AsyncLogEventInfo.Continuation #5

Closed snakefoot closed 6 years ago

snakefoot commented 6 years ago

https://github.com/smashraid/NLog.Splunk/blob/f51a01c4caf31cc08cb52ffd43bfa3bbf6a36b48/NLog.Splunk/NLog.Splunk/SplunkTarget.cs#L75

When overriding this method to allow batch processing, then you need to do some extra work:

    protected override void Write(AsyncLogEventInfo[] logEvents)
    {
        try
        {
            StringBuilder builder = new StringBuilder();

            foreach (AsyncLogEventInfo item in logEvents)
            {
                string json = BuildLog(item.LogEvent);
                builder.Append(json);
                builder.AppendLine();
            }
            this.WriteLogMessage(builder.ToString());
        }
        catch (Exception ex)
        {
           foreach (AsyncLogEventInfo item in logEvents)
                item.Continuation(ex);   // Notify error
           return;
        }

        foreach (AsyncLogEventInfo item in logEvents)
             item.Continuation(null);  // Notify success
    }
smashraid commented 6 years ago

Released v1.0.1