本文整理汇总了C#中MyTarget.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# MyTarget.Flush方法的具体用法?C# MyTarget.Flush怎么用?C# MyTarget.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyTarget
的用法示例。
在下文中一共展示了MyTarget.Flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlushTest
public void FlushTest()
{
var target = new MyTarget();
List<Exception> exceptions = new List<Exception>();
target.Initialize(CommonCfg);
target.Flush(exceptions.Add);
// flush was called
Assert.AreEqual(1, target.FlushCount);
Assert.AreEqual(2, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
Assert.AreEqual(1, exceptions.Count);
exceptions.ForEach(Assert.IsNull);
}
示例2: LockingTest
public void LockingTest()
{
var target = new MyTarget();
target.Initialize(null);
var mre = new ManualResetEvent(false);
Exception backgroundThreadException = null;
Thread t = new Thread(() =>
{
try
{
target.BlockingOperation(1000);
}
catch (Exception ex)
{
backgroundThreadException = ex;
}
finally
{
mre.Set();
}
});
target.Initialize(null);
t.Start();
Thread.Sleep(50);
List<Exception> exceptions = new List<Exception>();
target.WriteAsyncLogEvent(LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add));
target.WriteAsyncLogEvents(new[]
{
LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add),
LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add),
});
target.Flush(exceptions.Add);
target.Close();
exceptions.ForEach(Assert.IsNull);
mre.WaitOne();
if (backgroundThreadException != null)
{
Assert.Fail(backgroundThreadException.ToString());
}
}
示例3: FlushOnClosedTargetTest
public void FlushOnClosedTargetTest()
{
var target = new MyTarget();
target.Initialize(null);
target.Close();
Assert.Equal(1, target.InitializeCount);
Assert.Equal(1, target.CloseCount);
List<Exception> exceptions = new List<Exception>();
target.Flush(exceptions.Add);
Assert.Equal(1, exceptions.Count);
exceptions.ForEach(Assert.Null);
// flush was not called
Assert.Equal(2, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}