Exemplo n.º 1
0
        public virtual LogEntity Map(LogEvent logEvent)
        {
            var entity = new LogEntity
            {
                Timestamp = logEvent.Timestamp.ToUnixTimeMilliseconds(),
                Level     = logEvent.Level
            };

            entity.Message = logEvent.RenderMessage();

            entity.Exception = FormatException(logEvent.Exception);

            if (logEvent.Properties.TryGetValue(SourceContextPropertyName, out var sourceContext))
            {
                var sourceContextValue = ((ScalarValue)sourceContext).Value.ToString();
                entity.Category = sourceContextValue;
            }

            if (logEvent.Properties.TryGetValue(MachineNamePropertyName, out var machineName))
            {
                var machineNameValue = ((ScalarValue)machineName).Value.ToString();
                entity.Machine = machineNameValue;
            }

            if (logEvent.Properties.TryGetValue(ApplicationPropertyName, out var appName))
            {
                var appNameValue = ((ScalarValue)appName).Value.ToString();
                entity.Application = appNameValue;
            }

            if (logEvent.Properties.TryGetValue(TraceIdPropertyName, out var traceId))
            {
                var traceIdValue = ((ScalarValue)traceId).Value.ToString();
                entity.TraceId = traceIdValue;
            }

            return(entity);
        }
Exemplo n.º 2
0
 public abstract byte[] Serialize(LogEntity entity);