static logEvent Create(LoggingEvent loggingEvent) { 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 }; // 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); }
static void AddProperties(LoggingEvent loggingEvent, logEvent logEvent) { loggingEvent.Properties().Union(AppenderPropertiesFor(loggingEvent)). Do(pair => logEvent.properties.Add(pair)); }