public void ShouldFailIfAllAttemptsFailed() { var message = new GelfMessage(); for(var i = 0; i < retryCount; ++i) mainTransport.Expect(x => x.Send(message)).Throw(new Exception()); retryingTransport.Send(message); }
public byte[] Serialize(GelfMessage message) { var duration = message.Timestamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var result = new JsonObject { { "version", message.Version }, { "host", message.Host }, { "short_message", message.ShortMessage }, { "full_message", message.FullMessage }, { "timestamp", Math.Round(duration.TotalSeconds, 3, MidpointRounding.AwayFromZero) }, { "level", (int)message.Level } }; foreach (var additionalField in message.AdditionalFields) { var key = additionalField.Key; var value = additionalField.Value; var prefixedKey = key.StartsWith("_") ? key : "_" + key; if (!result.ContainsKey(prefixedKey)) { result.Add(prefixedKey, value); } else { _logger.Debug(string.Format( "Duplicate key {0} found. Key collisions are resolved by favoring the first key-value to be added.", prefixedKey)); } } return(Encoding.UTF8.GetBytes(result.ToString())); }
public void ShouldSendAgainIfFirstAttempFailed() { var message = new GelfMessage(); mainTransport.Expect(x => x.Send(message)).Throw(new Exception()); mainTransport.Expect(x => x.Send(message)).TentativeReturn(); retryingTransport.Send(message); }
public void ShouldSkipMessageIfSendFailed() { var countingTransport = new FailCountingTransport(); var bufferedTransport = new BufferedTransport(new SilentLogger(), countingTransport); for (var i = 0; i < MessageCount; ++i) { var message = new GelfMessage(); bufferedTransport.Send(message); } bufferedTransport.Close(); Assert.AreEqual(MessageCount, countingTransport.Count); }
public void ShouldSerializerSimpleMessage() { var dateTime = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var message = new GelfMessage { Host = "example.org", ShortMessage = "A short message that helps you identify what is going on", FullMessage = "Backtrace here\n\nmore stuff", Timestamp = dateTime, Level = GelfLevel.Alert, }; var serializedMessage = Encoding.UTF8.GetString(serializer.Serialize(message)); Assert.AreEqual("{\"version\":\"1.1\"," + "\"host\":\"example.org\"," + "\"short_message\":\"A short message that helps you identify what is going on\"," + "\"full_message\":\"Backtrace here\\n\\nmore stuff\"," + "\"timestamp\":1420070400," + "\"level\":1}", serializedMessage); }
public byte[] Serialize(GelfMessage message) { var duration = message.Timestamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var result = new JsonObject { {"message_version", message.Version}, {"host", message.Host}, {"short_message", message.ShortMessage}, {"full_message", message.FullMessage}, {"timestamp", Math.Round(duration.TotalSeconds, 3, MidpointRounding.AwayFromZero)}, {"level", (int)message.Level} }; foreach (var additionalField in message.AdditionalFields) { var key = additionalField.Key; var value = additionalField.Value; result.Add(key.StartsWith("_") ? key : "_" + key, value); } return Encoding.UTF8.GetBytes(result.ToString()); }
public byte[] Serialize(GelfMessage message) { var duration = message.Timestamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var result = new JsonObject { { "version", message.Version }, { "host", message.Host }, { "short_message", message.ShortMessage }, { "full_message", message.FullMessage }, { "timestamp", Math.Round(duration.TotalSeconds, 3, MidpointRounding.AwayFromZero) }, { "level", (int)message.Level } }; foreach (var additionalField in message.AdditionalFields) { var key = additionalField.Key; var value = additionalField.Value; result.Add(key.StartsWith("_") ? key : "_" + key, value); } return(Encoding.UTF8.GetBytes(result.ToString())); }
public void ShouldContinueWhenSendSuceed() { var message = new GelfMessage(); mainTransport.Expect(x => x.Send(message)).TentativeReturn(); retryingTransport.Send(message); }
public void Send(GelfMessage message) { Interlocked.Increment(ref count); throw new Exception(); }
public void Send(GelfMessage message) { Interlocked.Increment(ref count); }