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 void Publish(LogMessage logMessage) { if (string.IsNullOrEmpty(_host)) { return; } var str = _loggerFormatter.ApplyFormat(logMessage); var builder = new GelfMessageBuilder(str, "Heroes Rage, " + Application.platform); var level = GelfLevel.Debug; if (logMessage.Level == SimpleLogger.Logger.Level.Error) { level = GelfLevel.Error; } else if (logMessage.Level == SimpleLogger.Logger.Level.Warning) { level = GelfLevel.Warning; } builder.SetLevel(level); builder.SetTimestamp(DateTime.Now); if (!string.IsNullOrEmpty(_username)) { builder.SetAdditionalField("user_name", _username); } if (!string.IsNullOrEmpty(_buildVersion)) { builder.SetAdditionalField("build", _buildVersion); } if (!string.IsNullOrEmpty(_deviceName)) { builder.SetAdditionalField("device_name", _deviceName); } if (!string.IsNullOrEmpty(_deviceModel)) { builder.SetAdditionalField("device_model", _deviceModel); } if (!string.IsNullOrEmpty(_deviceUniqueIdentifier)) { builder.SetAdditionalField("device_id", _deviceUniqueIdentifier); } if (!string.IsNullOrEmpty(logMessage.CallingClass)) { builder.SetAdditionalField("calling_class", logMessage.CallingClass); } if (!string.IsNullOrEmpty(logMessage.CallingMethod)) { builder.SetAdditionalField("calling_method", logMessage.CallingMethod); } if (logMessage.LineNumber > 0) { builder.SetAdditionalField("line_number", logMessage.LineNumber.ToString()); } var mes = _gelfSerializer.Serialize(builder.ToMessage()); Debug.Log("Mes = " + mes); PushMessage(encoding.GetBytes(mes)); }