本文整理汇总了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());
}
示例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());
}