Ejemplo n.º 1
0
        private void Log(LogEventModel logEventModel)
        {
            var logEvent = new LogEventInfo
            {
                Level      = LogLevel.FromOrdinal((int)logEventModel.Level),
                LoggerName = logEventModel.LoggerSource,
                Message    = logEventModel.Message,
                TimeStamp  = logEventModel.TimeStamp
            };

            logEvent.Properties["ApplicationName"]  = logEventModel.ApplicationName;
            logEvent.Properties["CorrelationId"]    = logEventModel.CorrelationId;
            logEvent.Properties["MachineName"]      = logEventModel.MachineName;
            logEvent.Properties["MicroserviceName"] = logEventModel.MicroserviceName;
            logEvent.Properties["Exception"]        = logEventModel.Exception;

            var properties = logEventModel.CustomProperties as JObject;

            if (properties != null)
            {
                foreach (var property in properties.Properties())
                {
                    logEvent.Properties[property.Name] = property.Value;
                }
            }
            _logger.Log(logEvent);
        }
Ejemplo n.º 2
0
        private void Log(Level level, string message, Exception ex = null, Guid correlationId = default(Guid))
        {
            var logEventModel = new LogEventModel
            {
                MachineName      = machineName,
                ApplicationName  = applicationName,
                CorrelationId    = correlationId,
                Exception        = ex == null ? string.Empty : ex.ToString(),
                Level            = level,
                LoggerSource     = _loggerTypeName,
                Message          = message,
                MicroserviceName = microserviceName,
                TimeStamp        = DateTime.Now
            };

            Log(logEventModel);
        }