예제 #1
0
        public void LogObject <T>(Level level, LogDNAMeta <T> meta)
        {
            var obj = new LogDNAObject <T>
            {
                level    = level.Value,
                metatype = meta.Message.GetType().Name,
                meta     = meta
            };

            logdna.AddLine(new LogLine(app, JsonConvert.SerializeObject(obj, jsonSettings), DateTime.UtcNow));
        }
예제 #2
0
 protected override void Write(LogEventInfo logEvent)
 {
     apiClient.AddLine(new LogLine(ApplicationName, logEvent.FormattedMessage + "\r\n" + logEvent.Exception?.ToString(), logEvent.TimeStamp)
     {
         Level     = logEvent.Level.ToString().ToUpperInvariant(),
         Metadata  = logEvent.Properties,
         Exception = logEvent.Exception
     });
 }
        private void LogMessage(string logName, LogLevel logLevel, string message, object value)
        {
            var valueAsString = JsonConvert.SerializeObject(value,
                                                            new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            var messageDetail = _options.MessageDetailFactory.Create();

            messageDetail.Message = message;
            messageDetail.Level   = ConvertLevel(logLevel);
            messageDetail.Value   = new JRaw(valueAsString);
            messageDetail.Scope   = Scopes.Value?.Peek();

            int    length;
            string logLine;
            var    now = DateTime.UtcNow;

            do
            {
                logLine =
                    $"{now:yyyy-MM-dd HH:mm:ss} {JsonConvert.SerializeObject(messageDetail, new JsonSerializerSettings {ReferenceLoopHandling = ReferenceLoopHandling.Ignore})}";

                length = Encoding.UTF8.GetByteCount(logLine);

                if (length > MaxMessageSize)
                {
                    valueAsString = valueAsString.Substring(0, valueAsString.Length - 2);

                    // Deliberately not a JRaw at this point as we're starting to trim
                    // bits of the JSON string to make things fit into the 16KB limit.
                    // i.e. it's not valid JSON now.
                    messageDetail.Value = valueAsString;
                }
            } while (length > MaxMessageSize && valueAsString.Length > 0);

            _client.AddLine(new LogLine(logName, logLine));
        }