static void AddProperties(LoggingEvent loggingEvent, logEvent logEvent)
 {
     loggingEvent.Properties().Union(AppenderPropertiesFor(loggingEvent)).Do(pair => logEvent.properties.Add(pair));
 }
        static logEvent Create(
            LoggingEvent loggingEvent,
            MachineDataProvider machineDataProvider,
            Action <string, Exception> errorHandler)
        {
            var logEvent = new logEvent
            {
                loggerName = loggingEvent.LoggerName,
                domain     = loggingEvent.Domain,
                identity   = loggingEvent.Identity,
                threadName = loggingEvent.ThreadName,
                userName   = loggingEvent.UserName,
                timeStamp  = loggingEvent.TimeStamp.ToUniversalTime().ToString("O"),
                exception  = loggingEvent.ExceptionObject == null ? new object() : JsonSerializableException.Create(loggingEvent.ExceptionObject),
                message    = loggingEvent.RenderedMessage,
                fix        = loggingEvent.Fix.ToString(),
                hostName   = Environment.MachineName,
                level      = loggingEvent.Level == null ? null : loggingEvent.Level.DisplayName,
                machineIp  = machineDataProvider?.MachineExternalIp
            };

            try
            {
                if (logEvent.domain == Util.SystemInfo.NotAvailableText)
                {
                    logEvent.domain = Assembly.GetEntryAssembly().GetName().Name;
                }

                if (logEvent.userName == Util.SystemInfo.NotAvailableText)
                {
                    logEvent.userName = Environment.UserName;
                }
            }
            catch (Exception ex)
            {
                errorHandler("Exception occurred while adding properties to log event", ex);
            }

            // Added special handling of the MessageObject since it may be an exception.
            // Exception Types require specialized serialization to prevent serialization exceptions.
            if (loggingEvent.MessageObject != null && loggingEvent.MessageObject.GetType() != typeof(string))
            {
                if (loggingEvent.MessageObject is Exception)
                {
                    logEvent.messageObject = JsonSerializableException.Create((Exception)loggingEvent.MessageObject);
                }
                else
                {
                    logEvent.messageObject = loggingEvent.MessageObject;
                }
            }
            else
            {
                logEvent.messageObject = new object();
            }

            if (loggingEvent.LocationInformation != null)
            {
                logEvent.className  = loggingEvent.LocationInformation.ClassName;
                logEvent.fileName   = loggingEvent.LocationInformation.FileName;
                logEvent.lineNumber = loggingEvent.LocationInformation.LineNumber;
                logEvent.fullInfo   = loggingEvent.LocationInformation.FullInfo;
                logEvent.methodName = loggingEvent.LocationInformation.MethodName;
            }

            AddProperties(loggingEvent, logEvent);

            return(logEvent);
        }