当前位置: 首页>>代码示例>>C#>>正文


C# NetworkTarget.Flush方法代码示例

本文整理汇总了C#中NLog.Targets.NetworkTarget.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkTarget.Flush方法的具体用法?C# NetworkTarget.Flush怎么用?C# NetworkTarget.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NLog.Targets.NetworkTarget的用法示例。


在下文中一共展示了NetworkTarget.Flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NothingToFlushTest

        public void NothingToFlushTest()
        {
            var senderFactory = new MySenderFactory();
            var target = new NetworkTarget();
            target.Address = "tcp://${logger}.company.lan/";
            target.SenderFactory = senderFactory;
            target.Layout = "${message}";
            target.KeepConnection = true;
            target.Initialize(null);

            var mre = new ManualResetEvent(false);

            AsyncContinuation flushContinuation = ex =>
            {
                mre.Set();
            };

            target.Flush(flushContinuation);
            mre.WaitOne();
            target.Close();

            string expectedLog = @"";
            Assert.AreEqual(expectedLog, senderFactory.Log.ToString());
        }
开发者ID:rameshr,项目名称:NLog,代码行数:24,代码来源:NetworkTargetTests.cs

示例2: NetworkTargetMultipleConnectionsTest

        public void NetworkTargetMultipleConnectionsTest()
        {
            var senderFactory = new MySenderFactory();
            var target = new NetworkTarget();
            target.Address = "tcp://${logger}.company.lan/";
            target.SenderFactory = senderFactory;
            target.Layout = "${message}";
            target.KeepConnection = true;
            target.Initialize(null);

            var exceptions = new List<Exception>();
            var mre = new ManualResetEvent(false);
            int remaining = 3;
            AsyncContinuation asyncContinuation = ex =>
            {
                lock (exceptions)
                {
                    exceptions.Add(ex);
                    if (--remaining == 0)
                    {
                        mre.Set();
                    }
                }
            };

            target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger1", "msg1").WithContinuation(asyncContinuation));
            target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger2", "msg2").WithContinuation(asyncContinuation));
            target.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "logger3", "msg3").WithContinuation(asyncContinuation));

            mre.WaitOne();
            foreach (var ex in exceptions)
            {
                if (ex != null)
                {
                    Assert.Fail(ex.ToString());
                }
            }

            mre.Reset();
            AsyncContinuation flushContinuation = ex =>
            {
                mre.Set();
            };

            target.Flush(flushContinuation);
            mre.WaitOne();
            target.Close();

            string expectedLog = @"1: connect tcp://logger1.company.lan/
1: send 0 4
2: connect tcp://logger2.company.lan/
2: send 0 4
3: connect tcp://logger3.company.lan/
3: send 0 4
1: flush
2: flush
3: flush
1: close
2: close
3: close
";
            Assert.AreEqual(expectedLog, senderFactory.Log.ToString());
        }
开发者ID:rameshr,项目名称:NLog,代码行数:63,代码来源:NetworkTargetTests.cs


注:本文中的NLog.Targets.NetworkTarget.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。