コード例 #1
0
        public void LogglyTargetTagsTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}'>
                            <tag name='hello' />
                            <tag name='${logger}' />
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            logger.Info("Hello World");
            Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
            Assert.AreEqual(2, logglyClientMock.LogglyEvents[0].Options.Tags.Count);
            Assert.AreEqual("hello", logglyClientMock.LogglyEvents[0].Options.Tags[0].Value);
            Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Options.Tags[1].Value);
        }
コード例 #2
0
        public void LogglyTargetContextPropertyTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}' taskDelayMilliseconds='10'>
                            <contextproperty name='hello' layout='${logger}' />
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            logger.Info("Hello World");
            logglyClientMock.LogWritten.WaitOne(1000);
            Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
            Assert.Contains("hello", logglyClientMock.LogglyEvents[0].Data.KeyList);
            Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Data["hello"]);
        }
コード例 #3
0
        public void LogglyTargetMdlcTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}' includeMdlc='true'>
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            using (NLog.MappedDiagnosticsLogicalContext.SetScoped("hello", logger.Name))
            {
                logger.Info("Hello World");
                Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
                Assert.Contains("hello", logglyClientMock.LogglyEvents[0].Data.KeyList);
                Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Data["hello"]);
            }
        }