Beispiel #1
0
        public void ParseAndPrint(string input)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var templateAuto = logEventInfo.MessageTemplateParameters;
        }
Beispiel #2
0
 public void ThrowsTemplateParserException(string input)
 {
     Assert.Throws <TemplateParserException>(() =>
     {
         var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);
         logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
         var template = logEventInfo.MessageTemplateParameters;
     });
 }
Beispiel #3
0
        public void ParseNominal(string input)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var template = logEventInfo.MessageTemplateParameters;

            Assert.False(template.IsPositional);
        }
Beispiel #4
0
        private static void RenderAndTest(string input, CultureInfo culture, object[] args, string expected)
        {
            var logEventInfoAlways = new LogEventInfo(LogLevel.Info, "Logger", culture, input, args);

            logEventInfoAlways.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var templateAlways = logEventInfoAlways.MessageTemplateParameters;

            Assert.Equal(expected, logEventInfoAlways.FormattedMessage);
        }
Beispiel #5
0
        public void ParseName(string input, string name)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var template = logEventInfo.MessageTemplateParameters;

            Assert.Equal(1, template.Count);
            Assert.Equal(name, template[0].Name);
        }
Beispiel #6
0
        public void ParsePositional(string input, int index, string format)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var template = logEventInfo.MessageTemplateParameters;

            Assert.True(template.IsPositional);
            Assert.True(template.Count >= 1);
            Assert.Equal(format, template[0].Format);
            Assert.Equal(index, template[0].PositionalIndex);
        }
Beispiel #7
0
        public void ParseFormatAndAlignment_text(string input, int?alignment, string format)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var template = logEventInfo.MessageTemplateParameters;

            Assert.Equal(1, template.Count);
            var hole = template[0];

            Assert.False(template.IsPositional);
            Assert.Equal("car", hole.Name);
            Assert.Equal(format, hole.Format);
            Assert.NotNull(alignment);
        }
Beispiel #8
0
        public void ParseHoleType(string input, string holeType)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "Logger", null, input, ManyParameters);

            logEventInfo.SetMessageFormatter(new NLog.Internal.LogMessageTemplateFormatter(LogManager.LogFactory.ServiceRepository, true, false).MessageFormatter, null);
            var template = logEventInfo.MessageTemplateParameters;

            Assert.Equal(1, template.Count);
            CaptureType captureType = CaptureType.Normal;

            if (holeType == "@")
            {
                captureType = CaptureType.Serialize;
            }
            else if (holeType == "$")
            {
                captureType = CaptureType.Stringify;
            }
            Assert.Equal(captureType, template[0].CaptureType);
        }