Ejemplo n.º 1
0
        /// <summary>
        /// Internal log mechanism for logging log entries to log files and database
        /// </summary>
        /// <param name="logEntry"></param>
        /// <param name="level"></param>
        private void InternalLog(LogEntry logEntry, LogLevel level)
        {
            if (logEntry == null)
            {
                return;
            }

            logEntry.Level = level.AsInternal().ToString();
            BeautifyActionData(logEntry);
            var message = CreateMessage(logEntry);

            var loggerName = logEntry?.Action ?? "default";
            var logger     = LogManager.GetLogger(loggerName);

            var logEvent = new LogEventInfo(level, loggerName, message);

            logEvent.Properties[nameof(logEntry.Level)]                  = logEntry.Level;
            logEvent.Properties[nameof(logEntry.ErrorGroup)]             = logEntry.ErrorGroup;
            logEvent.Properties[nameof(logEntry.ErrorCode)]              = logEntry.ErrorCode;
            logEvent.Properties[nameof(logEntry.Origin)]                 = logEntry.Origin;
            logEvent.Properties[nameof(logEntry.Action)]                 = logEntry.Action;
            logEvent.Properties[nameof(logEntry.ProcessName)]            = logEntry.ProcessName;
            logEvent.Properties[nameof(logEntry.ActionFilePath)]         = logEntry.ActionFilePath;
            logEvent.Properties[nameof(logEntry.ActionSourceLineNumber)] = logEntry.ActionSourceLineNumber;
            logEvent.Properties[nameof(logEntry.Message)]                = logEntry.Message;
            logEvent.Properties[nameof(logEntry.ExceptionMessage)]       = logEntry.ExceptionMessage;
            logEvent.Properties[nameof(logEntry.UserIdentifier)]         = logEntry.UserIdentifier;
            logEvent.Properties[nameof(logEntry.Payload)]                = logEntry.Payload;


            logger.Log(logEvent);
        }