/// <summary>
        /// Checks if the already parsed input message-parameters must be sent through
        /// the NLog MessageTemplate Parser for proper handling of message-template syntax (Ex. @)
        /// </summary>
        /// <remarks>
        /// Using the NLog MessageTemplate Parser will hurt performance: 1 x Microsoft Parser - 2 x NLog Parser - 1 x NLog Formatter
        /// </remarks>
        private LogEventInfo TryParseMessageTemplate(LogLevel nLogLogLevel, IReadOnlyList <KeyValuePair <string, object> > messageProperties, NLogMessageParameterList messageParameters)
        {
            if (messageParameters?.HasMessageTemplateSyntax(_options.ParseMessageTemplates) == true)
            {
                var originalMessage           = messageParameters.GetOriginalMessage(messageProperties);
                var logEvent                  = new LogEventInfo(nLogLogLevel, _logger.Name, null, originalMessage, SingleItemArray);
                var messageTemplateParameters = logEvent.MessageTemplateParameters;   // Forces parsing of OriginalMessage
                if (messageTemplateParameters.Count > 0)
                {
                    // We have parsed the message and found parameters, now we need to do the parameter mapping
                    CaptureLogEventInfoParameters(logEvent, messageParameters, messageTemplateParameters);
                    return(logEvent);
                }

                return(null);    // Parsing not possible
            }

            return(null);    // Parsing not needed
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the already parsed input message-parameters must be sent through
        /// the NLog MessageTemplate Parser for proper handling of message-template syntax.
        /// </summary>
        /// <remarks>
        /// Using the NLog MesageTemplate Parser will hurt performance: 1 x Microsoft Parser - 2 x NLog Parser - 1 x NLog Formatter
        /// </remarks>
        private LogEventInfo TryParseMessageTemplate(LogLevel nLogLogLevel, IReadOnlyList <KeyValuePair <string, object> > messageProperties, out NLogMessageParameterList messageParameters)
        {
            messageParameters = TryParseMessageParameterList(messageProperties);

            if (messageParameters?.HasMessageTemplateSyntax(_options.ParseMessageTemplates) == true)
            {
                var originalMessage            = messageParameters.GetOriginalMessage(messageProperties);
                var eventInfo                  = new LogEventInfo(nLogLogLevel, _logger.Name, null, originalMessage, _singleItemArray);
                var messagetTemplateParameters = eventInfo.MessageTemplateParameters;   // Forces parsing of OriginalMessage
                if (messagetTemplateParameters.Count > 0)
                {
                    // We have parsed the message and found parameters, now we need to do the parameter mapping
                    eventInfo.Parameters = CreateLogEventInfoParameters(messageParameters, messagetTemplateParameters, out var extraProperties);
                    AddExtraPropertiesToLogEvent(eventInfo, extraProperties);
                    return(eventInfo);
                }

                return(null);    // Parsing not possible
            }

            return(null);    // Parsing not needed
        }