Esempio n. 1
0
        void ConfigureLogger(NLog.Config.LoggingConfiguration config)
        {
            var jsonParams = new Dictionary <string, string>()
            {
                { "hoge", "fuga" },
                { "foo", "bar" }
            };

            // initialize targets
            var ucTarget = NLogFactory.CreateUnityConsoleTarget("UCTargetByCode");
            var wsTarget = NLogFactory.CreateJsonWebServiceTarget("JWSTargetByCode", "http://localhost:1234/nlog", jsonParams);
            var mTarget  = new MemoryTarget("MTargetByCode");

            mTarget.Layout = "[${level:uppercase=true}] ${message}";

            // add rules
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, ucTarget);
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, wsTarget);
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, mTarget);
        }
Esempio n. 2
0
        public void TestCreateJsonWebServiceTarget()
        {
            var wsTargetWithUrl = NLogFactory.CreateJsonWebServiceTarget("http://localhost:5001/nlog");

            Assert.AreEqual(null, wsTargetWithUrl.Name);
            Assert.AreEqual("http://localhost:5001/nlog", wsTargetWithUrl.Url.OriginalString);
            Assert.AreEqual(6, wsTargetWithUrl.Parameters.Count);
            Assert.AreEqual(WebServiceProtocol.JsonPost, wsTargetWithUrl.Protocol);

            var wsTargetWithName = NLogFactory.CreateJsonWebServiceTarget("WSTarget", "http://localhost:5001/nlog");

            Assert.AreEqual("WSTarget", wsTargetWithName.Name);
            Assert.AreEqual("http://localhost:5001/nlog", wsTargetWithName.Url.OriginalString);
            Assert.AreEqual(6, wsTargetWithName.Parameters.Count);
            Assert.AreEqual(WebServiceProtocol.JsonPost, wsTargetWithName.Protocol);

            var jsonParams = new Dictionary <string, string>()
            {
                { "param1", "value1" },
                { "param2", "value2" }
            };

            var wsTargetWithParams = NLogFactory.CreateJsonWebServiceTarget("http://localhost:5001/nlog", jsonParams);

            Assert.AreEqual(null, wsTargetWithParams.Name);
            Assert.AreEqual("http://localhost:5001/nlog", wsTargetWithParams.Url.OriginalString);
            Assert.AreEqual(2, wsTargetWithParams.Parameters.Count);
            Assert.AreEqual(WebServiceProtocol.JsonPost, wsTargetWithParams.Protocol);

            var wsTargetWithNameAndParams = NLogFactory.CreateJsonWebServiceTarget("WSTarget", "http://localhost:5001/nlog", jsonParams);

            Assert.AreEqual("WSTarget", wsTargetWithNameAndParams.Name);
            Assert.AreEqual("http://localhost:5001/nlog", wsTargetWithNameAndParams.Url.OriginalString);
            Assert.AreEqual(2, wsTargetWithNameAndParams.Parameters.Count);
            Assert.AreEqual(WebServiceProtocol.JsonPost, wsTargetWithNameAndParams.Protocol);
        }