本文整理汇总了C#中LogEventInfo.WithContinuation方法的典型用法代码示例。如果您正苦于以下问题:C# LogEventInfo.WithContinuation方法的具体用法?C# LogEventInfo.WithContinuation怎么用?C# LogEventInfo.WithContinuation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogEventInfo
的用法示例。
在下文中一共展示了LogEventInfo.WithContinuation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoFlushTargetWrapperSyncTest1
public void AutoFlushTargetWrapperSyncTest1()
{
var myTarget = new MyTarget();
var wrapper = new AutoFlushTargetWrapper
{
WrappedTarget = myTarget,
};
myTarget.Initialize(null);
wrapper.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
bool continuationHit = false;
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit = true;
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.IsTrue(continuationHit);
Assert.IsNull(lastException);
Assert.AreEqual(1, myTarget.FlushCount);
Assert.AreEqual(1, myTarget.WriteCount);
continuationHit = false;
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.IsTrue(continuationHit);
Assert.IsNull(lastException);
Assert.AreEqual(2, myTarget.WriteCount);
Assert.AreEqual(2, myTarget.FlushCount);
}
示例2: FilteringTargetWrapperAsyncTest2
public void FilteringTargetWrapperAsyncTest2()
{
var myMockCondition = new MyMockCondition(false);
var myTarget = new MyAsyncTarget();
var wrapper = new FilteringTargetWrapper(myTarget, myMockCondition);
wrapper.Initialize(CommonCfg);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
Action<Exception> continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(0, myTarget.WriteCount);
Assert.AreEqual(1, myMockCondition.CallCount);
continuationHit.Reset();
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(0, myTarget.WriteCount);
Assert.AreEqual(2, myMockCondition.CallCount);
}
示例3: AsyncTargetWrapperAsyncTest1
public void AsyncTargetWrapperAsyncTest1()
{
var myTarget = new MyAsyncTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget) { Name = "AsyncTargetWrapperAsyncTest1_Wrapper" };
targetWrapper.Initialize(null);
myTarget.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.True(continuationHit.WaitOne());
Assert.Null(lastException);
Assert.Equal(1, myTarget.WriteCount);
continuationHit.Reset();
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.Null(lastException);
Assert.Equal(2, myTarget.WriteCount);
}
示例4: FilteringTargetWrapperSyncTest1
public void FilteringTargetWrapperSyncTest1()
{
var myMockCondition = new MyMockCondition(true);
var myTarget = new MyTarget();
var wrapper = new FilteringTargetWrapper
{
WrappedTarget = myTarget,
Condition = myMockCondition,
};
myTarget.Initialize(null);
wrapper.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
bool continuationHit = false;
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit = true;
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.Equal(1, myMockCondition.CallCount);
Assert.True(continuationHit);
Assert.Null(lastException);
Assert.Equal(1, myTarget.WriteCount);
continuationHit = false;
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.True(continuationHit);
Assert.Null(lastException);
Assert.Equal(2, myTarget.WriteCount);
Assert.Equal(2, myMockCondition.CallCount);
}
示例5: AsyncTargetWrapperSyncTest1
public void AsyncTargetWrapperSyncTest1()
{
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper
{
WrappedTarget = myTarget,
};
targetWrapper.Initialize(null);
myTarget.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
ManualResetEvent continuationHit = new ManualResetEvent(false);
Thread continuationThread = null;
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationThread = Thread.CurrentThread;
continuationHit.Set();
};
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
// continuation was not hit
Assert.True(continuationHit.WaitOne(2000));
Assert.NotSame(continuationThread, Thread.CurrentThread);
Assert.Null(lastException);
Assert.Equal(1, myTarget.WriteCount);
continuationHit.Reset();
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.NotSame(continuationThread, Thread.CurrentThread);
Assert.Null(lastException);
Assert.Equal(2, myTarget.WriteCount);
}
示例6: AsyncTargetWrapperAsyncWithExceptionTest1
public void AsyncTargetWrapperAsyncWithExceptionTest1()
{
var myTarget = new MyAsyncTarget
{
ThrowExceptions = true,
};
var targetWrapper = new AsyncTargetWrapper(myTarget);
targetWrapper.Initialize(null);
myTarget.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.True(continuationHit.WaitOne());
Assert.NotNull(lastException);
Assert.IsType(typeof(InvalidOperationException), lastException);
// no flush on exception
Assert.Equal(0, myTarget.FlushCount);
Assert.Equal(1, myTarget.WriteCount);
continuationHit.Reset();
lastException = null;
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.NotNull(lastException);
Assert.IsType(typeof(InvalidOperationException), lastException);
Assert.Equal(0, myTarget.FlushCount);
Assert.Equal(2, myTarget.WriteCount);
}
示例7: AsyncTargetWrapperSyncTest_WhenTimeToSleepBetweenBatchesIsEqualToZero
public void AsyncTargetWrapperSyncTest_WhenTimeToSleepBetweenBatchesIsEqualToZero()
{
LogManager.ThrowConfigExceptions = true;
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper() {
WrappedTarget = myTarget,
TimeToSleepBetweenBatches = 0,
BatchSize = 4,
QueueLimit = 2, // Will make it "sleep" between every second write
OverflowAction = AsyncTargetWrapperOverflowAction.Block
};
targetWrapper.Initialize(null);
myTarget.Initialize(null);
try
{
int flushCounter = 0;
AsyncContinuation flushHandler = (ex) => { ++flushCounter; };
List<KeyValuePair<LogEventInfo, AsyncContinuation>> itemPrepareList = new List<KeyValuePair<LogEventInfo, AsyncContinuation>>(2500);
List<int> itemWrittenList = new List<int>(itemPrepareList.Capacity);
for (int i = 0; i< itemPrepareList.Capacity; ++i)
{
var logEvent = new LogEventInfo();
int sequenceID = logEvent.SequenceID;
itemPrepareList.Add(new KeyValuePair<LogEventInfo, AsyncContinuation>(logEvent, (ex) => itemWrittenList.Add(sequenceID)));
}
long startTicks = Environment.TickCount;
for (int i = 0; i < itemPrepareList.Count; ++i)
{
var logEvent = itemPrepareList[i].Key;
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(itemPrepareList[i].Value));
}
targetWrapper.Flush(flushHandler);
for (int i = 0; i < itemPrepareList.Count * 2 && itemWrittenList.Count != itemPrepareList.Count; ++i)
System.Threading.Thread.Sleep(1);
long elapsedMilliseconds = Environment.TickCount - startTicks;
Assert.Equal(itemPrepareList.Count, itemWrittenList.Count);
int prevSequenceID = 0;
for (int i = 0; i < itemWrittenList.Count; ++i)
{
Assert.True(prevSequenceID < itemWrittenList[i]);
prevSequenceID = itemWrittenList[i];
}
#if MONO || NET3_5
Assert.True(elapsedMilliseconds < 2500); // Skip timing test when running within OpenCover.Console.exe
#endif
targetWrapper.Flush(flushHandler);
for (int i = 0; i < 2000 && flushCounter != 2; ++i)
System.Threading.Thread.Sleep(1);
Assert.Equal(2, flushCounter);
}
finally
{
myTarget.Close();
targetWrapper.Close();
}
}
示例8: AutoFlushTargetWrapperAsyncTest1
public void AutoFlushTargetWrapperAsyncTest1()
{
var myTarget = new MyAsyncTarget();
var wrapper = new AutoFlushTargetWrapper(myTarget);
myTarget.Initialize(null);
wrapper.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(1, myTarget.FlushCount);
Assert.AreEqual(1, myTarget.WriteCount);
continuationHit.Reset();
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(2, myTarget.WriteCount);
Assert.AreEqual(2, myTarget.FlushCount);
}
示例9: FilteringTargetWrapperAsyncWithExceptionTest1
public void FilteringTargetWrapperAsyncWithExceptionTest1()
{
var myMockCondition = new MyMockCondition(true);
var myTarget = new MyAsyncTarget
{
ThrowExceptions = true,
};
var wrapper = new FilteringTargetWrapper(myTarget, myMockCondition);
myTarget.Initialize(null);
wrapper.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNotNull(lastException);
Assert.IsInstanceOfType(typeof(InvalidOperationException), lastException);
Assert.AreEqual(1, myTarget.WriteCount);
Assert.AreEqual(1, myMockCondition.CallCount);
continuationHit.Reset();
lastException = null;
wrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.IsNotNull(lastException);
Assert.IsInstanceOfType(typeof(InvalidOperationException), lastException);
Assert.AreEqual(2, myTarget.WriteCount);
Assert.AreEqual(2, myMockCondition.CallCount);
}
示例10: WriteToTargetWithFilterChain
private static bool WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException)
{
Target target = targetListHead.Target;
FilterResult result = GetFilterResult(targetListHead.FilterChain, logEvent);
if ((result == FilterResult.Ignore) || (result == FilterResult.IgnoreFinal))
{
if (InternalLogger.IsDebugEnabled)
{
InternalLogger.Debug("{0}.{1} Rejecting message because of a filter.", logEvent.LoggerName, logEvent.Level);
}
if (result == FilterResult.IgnoreFinal)
{
return false;
}
return true;
}
target.WriteAsyncLogEvent(logEvent.WithContinuation(onException));
if (result == FilterResult.LogFinal)
{
return false;
}
return true;
}