Exemplo n.º 1
0
        public static LogEvent ReadFromJObject(JObject jObject)
        {
            if (!jObject.TryGetValue("@t", out _))
            {
                jObject.Add("@t", new JValue(DateTime.UtcNow.ToString("O")));
            }

            if (jObject.TryGetValue("@l", out var levelToken))
            {
                jObject.Remove("@l");

                var serilogLevel = LevelMapping.ToSerilogLevel(levelToken.Value <string>());
                if (serilogLevel != LogEventLevel.Information)
                {
                    jObject.Add("@l", new JValue(serilogLevel.ToString()));
                }

                jObject.Add(SurrogateLevelProperty.PropertyName, levelToken);
            }
            else
            {
                jObject.Add(SurrogateLevelProperty.PropertyName, new JValue("Information"));
            }

            return(LogEventReader.ReadFromJObject(jObject));
        }
Exemplo n.º 2
0
 LogEvent ToSerilogEvent(EventEntity evt)
 {
     return(new LogEvent(
                DateTimeOffset.ParseExact(evt.Timestamp, "o", CultureInfo.InvariantCulture).ToLocalTime(),
                LevelMapping.ToSerilogLevel(evt.Level),
                string.IsNullOrWhiteSpace(evt.Exception) ? null : new TextException(evt.Exception),
                new MessageTemplate(evt.MessageTemplateTokens.Select(ToMessageTemplateToken)),
                evt.Properties.Select(p => CreateProperty(p.Name, p.Value))));
 }
Exemplo n.º 3
0
        LogEvent ReadSerilogEvent(string clef, out string eventId, out uint eventType)
        {
            var jvalue = new JsonTextReader(new StringReader(clef));

            if (!(_serializer.Deserialize <JToken>(jvalue) is JObject jobject))
            {
                throw new InvalidDataException($"The line is not a JSON object: `{clef.Trim()}`.");
            }

            if (jobject.TryGetValue("@l", out var levelToken))
            {
                jobject.Remove("@l");
                jobject.Add("@l", new JValue(LevelMapping.ToSerilogLevel(levelToken.Value <string>()).ToString()));
            }

            var raw = LogEventReader.ReadFromJObject(jobject);

            eventId = "event-0";
            if (raw.Properties.TryGetValue("@seqid", out var id) &&
                id is ScalarValue {
                Value : string sid
            })
Exemplo n.º 4
0
        LogEvent ReadSerilogEvent(string clef, out string eventId, out uint eventType)
        {
            var jvalue = new JsonTextReader(new StringReader(clef));

            if (!(_serializer.Deserialize <JToken>(jvalue) is JObject jobject))
            {
                throw new InvalidDataException($"The line is not a JSON object: `{clef.Trim()}`.");
            }

            if (jobject.TryGetValue("@l", out var levelToken))
            {
                jobject.Remove("@l");
                jobject.Add("@l", new JValue(LevelMapping.ToSerilogLevel(levelToken.Value <string>()).ToString()));
            }

            var raw = LogEventReader.ReadFromJObject(jobject);

            eventId = "event-0";
            if (raw.Properties.TryGetValue("@seqid", out var id) &&
                id is ScalarValue svid &&
                svid.Value is string sid)
            {
                eventId = sid;
            }

            eventType = 0u;
            if (raw.Properties.TryGetValue("@i", out var et) &&
                et is ScalarValue svet &&
                svet.Value is string set &&
                uint.TryParse(set, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var uet))
            {
                eventType = uet;
            }

            return(raw);
        }