Esempio n. 1
0
        public void CompoundTest()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(@"
            <nlog>
                <targets>
                    <target name='rr' type='RoundRobinGroup'>
                        <target name='d1' type='Debug' layout='${message}1' />
                        <target name='d2' type='Debug' layout='${message}2' />
                        <target name='d3' type='Debug' layout='${message}3' />
                        <target name='d4' type='Debug' layout='${message}4' />
                    </target>
                </targets>
            </nlog>");

            LoggingConfiguration c = new XmlLoggingConfiguration(doc.DocumentElement, null);

            Assert.IsNotNull(c.FindTargetByName("rr"));
            Assert.IsNotNull(c.FindTargetByName("d1"));
            Assert.IsNotNull(c.FindTargetByName("d2"));
            Assert.IsNotNull(c.FindTargetByName("d3"));
            Assert.IsNotNull(c.FindTargetByName("d4"));

            Assert.IsInstanceOfType(typeof(RoundRobinTarget), c.FindTargetByName("rr"));
            Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d1"));
            Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d2"));
            Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d3"));
            Assert.IsInstanceOfType(typeof(DebugTarget), c.FindTargetByName("d4"));

            RoundRobinTarget rr = c.FindTargetByName("rr") as RoundRobinTarget;
            DebugTarget      d1 = c.FindTargetByName("d1") as DebugTarget;
            DebugTarget      d2 = c.FindTargetByName("d2") as DebugTarget;
            DebugTarget      d3 = c.FindTargetByName("d3") as DebugTarget;
            DebugTarget      d4 = c.FindTargetByName("d4") as DebugTarget;

            Assert.AreEqual(4, rr.Targets.Count);
            Assert.AreSame(d1, rr.Targets[0]);
            Assert.AreSame(d2, rr.Targets[1]);
            Assert.AreSame(d3, rr.Targets[2]);
            Assert.AreSame(d4, rr.Targets[3]);

            Assert.AreEqual(d1.Layout, "${message}1");
            Assert.AreEqual(d2.Layout, "${message}2");
            Assert.AreEqual(d3.Layout, "${message}3");
            Assert.AreEqual(d4.Layout, "${message}4");
        }
Esempio n. 2
0
    static void Main(string[] args)
    {
        FileTarget file1 = new FileTarget();

        file1.FileName = "${basedir}/file1.txt";

        FileTarget file2 = new FileTarget();

        file2.FileName = "${basedir}/file2.txt";

        RoundRobinTarget target = new RoundRobinTarget();

        target.Targets.Add(file1);
        target.Targets.Add(file2);

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");

        logger.Debug("log message");
    }