Beispiel #1
0
        private string GetMessageString(LogEventInfo logEvent)
        {
            if (!UseJSON)
            {
                return(RenderLogEvent(Layout, logEvent));
            }
            else
            {
                var message = this.UseLayoutAsMessage ? RenderLogEvent(Layout, logEvent) : logEvent.FormattedMessage;
                var fullContextProperties = GetFullContextProperties(logEvent);
                var messageSource         = RenderLogEvent(MessageSource, logEvent);
                if (string.IsNullOrEmpty(messageSource))
                {
                    messageSource = string.Format("nlog://{0}/{1}", System.Net.Dns.GetHostName(), logEvent.LoggerName);
                }

                try
                {
                    var jsonSerializer = JsonSerializer;
                    lock (jsonSerializer)
                    {
                        return(MessageFormatter.GetMessageInner(jsonSerializer, message, messageSource, logEvent, Fields, fullContextProperties));
                    }
                }
                catch (Exception e)
                {
                    _jsonSerializer = null; // reset as it it might be broken
                    InternalLogger.Error(e, "RabbitMQTarget(Name={0}): Failed to serialize LogEvent: {1}", Name, e.Message);
                    throw;
                }
            }
        }
Beispiel #2
0
        private byte[] GetMessage(LogEventInfo info)
        {
            var msg = MessageFormatter.GetMessageInner(UseJSON, this.UseLayoutAsMessage, Layout, info, this.Fields);

            return(_Encoding.GetBytes(msg));
        }
Beispiel #3
0
        private byte[] GetMessage(LogEventInfo info)
        {
            string messageInner = MessageFormatter.GetMessageInner(this.UseJSON, this.UseLayoutAsMessage, this.Layout, info, this.Fields);

            return(this._Encoding.GetBytes(messageInner));
        }