本文整理汇总了C#中MyTarget.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# MyTarget.Initialize方法的具体用法?C# MyTarget.Initialize怎么用?C# MyTarget.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyTarget
的用法示例。
在下文中一共展示了MyTarget.Initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoubleInitializeTest
public void DoubleInitializeTest()
{
var target = new MyTarget();
target.Initialize(CommonCfg);
target.Initialize(CommonCfg);
// initialize was called once
Assert.AreEqual(1, target.InitializeCount);
Assert.AreEqual(1, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例2: 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);
}
示例3: InitializeTest
public void InitializeTest()
{
var target = new MyTarget();
target.Initialize(null);
// initialize was called once
Assert.Equal(1, target.InitializeCount);
Assert.Equal(1, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例4: DoubleCloseTest
public void DoubleCloseTest()
{
var target = new MyTarget();
using (target.Initialize(CommonCfg))
{
}
// initialize and close were called once each
Assert.AreEqual(1, target.InitializeCount);
Assert.AreEqual(1, target.CloseCount);
Assert.AreEqual(2, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例5: DoubleCloseTest
public void DoubleCloseTest()
{
var target = new MyTarget();
target.Initialize(null);
target.Close();
target.Close();
// initialize and close were called once each
Assert.Equal(1, target.InitializeCount);
Assert.Equal(1, target.CloseCount);
Assert.Equal(2, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例6: 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);
}
示例7: RoundRobinGroupTargetSyncTest1
public void RoundRobinGroupTargetSyncTest1()
{
var myTarget1 = new MyTarget();
var myTarget2 = new MyTarget();
var myTarget3 = new MyTarget();
var wrapper = new RoundRobinGroupTarget()
{
Targets = { myTarget1, myTarget2, myTarget3 },
};
myTarget1.Initialize(null);
myTarget2.Initialize(null);
myTarget3.Initialize(null);
wrapper.Initialize(null);
List<Exception> exceptions = new List<Exception>();
// no exceptions
for (int i = 0; i < 10; ++i)
{
wrapper.WriteAsyncLogEvent(LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add));
}
Assert.Equal(10, exceptions.Count);
foreach (var e in exceptions)
{
Assert.Null(e);
}
Assert.Equal(4, myTarget1.WriteCount);
Assert.Equal(3, myTarget2.WriteCount);
Assert.Equal(3, myTarget3.WriteCount);
Exception flushException = null;
var flushHit = new ManualResetEvent(false);
wrapper.Flush(ex => { flushException = ex; flushHit.Set(); });
flushHit.WaitOne();
if (flushException != null)
{
Assert.True(false, flushException.ToString());
}
Assert.Equal(1, myTarget1.FlushCount);
Assert.Equal(1, myTarget2.FlushCount);
Assert.Equal(1, myTarget3.FlushCount);
}
示例8: PostFilteringTargetWrapperUsingDefaultFilterTest
public void PostFilteringTargetWrapperUsingDefaultFilterTest()
{
var target = new MyTarget();
var wrapper = new PostFilteringTargetWrapper()
{
WrappedTarget = target,
Rules =
{
// if we had any warnings, log debug too
new FilteringRule("level >= LogLevel.Warn", "level >= LogLevel.Debug"),
// when there is an error, emit everything
new FilteringRule
{
Exists = "level >= LogLevel.Error",
Filter = "true",
},
},
// by default log info and above
DefaultFilter = "level >= LogLevel.Info",
};
wrapper.Initialize(null);
target.Initialize(null);
var exceptions = new List<Exception>();
var events = new []
{
new LogEventInfo(LogLevel.Debug, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger2", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Debug, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Trace, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger3", "Hello").WithContinuation(exceptions.Add),
};
wrapper.WriteAsyncLogEvents(events);
// make sure all Info events went through
Assert.Equal(3, target.Events.Count);
Assert.Same(events[1].LogEvent, target.Events[0]);
Assert.Same(events[2].LogEvent, target.Events[1]);
Assert.Same(events[5].LogEvent, target.Events[2]);
Assert.Equal(events.Length, exceptions.Count);
}
示例9: InitializeFailedTest
public void InitializeFailedTest()
{
var target = new MyTarget();
target.ThrowOnInitialize = true;
LogManager.ThrowExceptions = true;
Assert.Throws<InvalidOperationException>(() => target.Initialize(null));
// after exception in Initialize(), the target becomes non-functional and all Write() operations
var exceptions = new List<Exception>();
target.WriteAsyncLogEvent(LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add));
Assert.Equal(0, target.WriteCount);
Assert.Equal(1, exceptions.Count);
Assert.NotNull(exceptions[0]);
Assert.Equal("Target " + target + " failed to initialize.", exceptions[0].Message);
Assert.Equal("Init error.", exceptions[0].InnerException.Message);
}
示例10: RetryingTargetWrapperTest1
public void RetryingTargetWrapperTest1()
{
var target = new MyTarget();
var wrapper = new RetryingTargetWrapper()
{
WrappedTarget = target,
RetryCount = 10,
RetryDelayMilliseconds = 1,
};
wrapper.Initialize(null);
target.Initialize(null);
var exceptions = new List<Exception>();
var events = new []
{
new LogEventInfo(LogLevel.Debug, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger2", "Hello").WithContinuation(exceptions.Add),
};
wrapper.WriteAsyncLogEvents(events);
// make sure all events went through
Assert.AreEqual(3, target.Events.Count);
Assert.AreSame(events[0].LogEvent, target.Events[0]);
Assert.AreSame(events[1].LogEvent, target.Events[1]);
Assert.AreSame(events[2].LogEvent, target.Events[2]);
Assert.AreEqual(events.Length, exceptions.Count, "Some continuations were not invoked.");
// make sure there were no exception
foreach (var ex in exceptions)
{
Assert.IsNull(ex);
}
}
示例11: 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);
}
示例12: 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);
}
示例13: RepeatingTargetWrapperTest1
public void RepeatingTargetWrapperTest1()
{
var target = new MyTarget();
var wrapper = new RepeatingTargetWrapper()
{
WrappedTarget = target,
RepeatCount = 3,
};
wrapper.Initialize(null);
target.Initialize(null);
var exceptions = new List<Exception>();
var events = new[]
{
new LogEventInfo(LogLevel.Debug, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger1", "Hello").WithContinuation(exceptions.Add),
new LogEventInfo(LogLevel.Info, "Logger2", "Hello").WithContinuation(exceptions.Add),
};
wrapper.WriteAsyncLogEvents(events);
// make sure all events went through and were replicated 3 times
Assert.Equal(9, target.Events.Count);
Assert.Same(events[0].LogEvent, target.Events[0]);
Assert.Same(events[0].LogEvent, target.Events[1]);
Assert.Same(events[0].LogEvent, target.Events[2]);
Assert.Same(events[1].LogEvent, target.Events[3]);
Assert.Same(events[1].LogEvent, target.Events[4]);
Assert.Same(events[1].LogEvent, target.Events[5]);
Assert.Same(events[2].LogEvent, target.Events[6]);
Assert.Same(events[2].LogEvent, target.Events[7]);
Assert.Same(events[2].LogEvent, target.Events[8]);
Assert.Equal(events.Length, exceptions.Count);
}
示例14: AutoFlushOnConditionTest
public void AutoFlushOnConditionTest()
{
var testTarget = new MyTarget();
var autoFlushWrapper = new AutoFlushTargetWrapper(testTarget);
autoFlushWrapper.Condition = "level > LogLevel.Info";
testTarget.Initialize(null);
autoFlushWrapper.Initialize(null);
AsyncContinuation continuation = ex => { };
autoFlushWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Info, "*", "test").WithContinuation(continuation));
autoFlushWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Trace, "*", "test").WithContinuation(continuation));
Assert.Equal(2, testTarget.WriteCount);
Assert.Equal(0, testTarget.FlushCount);
autoFlushWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Warn, "*", "test").WithContinuation(continuation));
autoFlushWrapper.WriteAsyncLogEvent(LogEventInfo.Create(LogLevel.Error, "*", "test").WithContinuation(continuation));
Assert.Equal(4, testTarget.WriteCount);
Assert.Equal(2, testTarget.FlushCount);
}
示例15: SplitGroupSyncTest1inner
private static void SplitGroupSyncTest1inner(bool allEventsAtOnce)
{
var myTarget1 = new MyTarget();
var myTarget2 = new MyTarget();
var myTarget3 = new MyTarget();
var wrapper = new SplitGroupTarget()
{
Targets = { myTarget1, myTarget2, myTarget3 },
};
myTarget1.Initialize(null);
myTarget2.Initialize(null);
myTarget3.Initialize(null);
wrapper.Initialize(null);
List<Exception> exceptions = new List<Exception>();
var inputEvents = new List<LogEventInfo>();
for (int i = 0; i < 10; ++i)
{
inputEvents.Add(LogEventInfo.CreateNullEvent());
}
int remaining = inputEvents.Count;
var allDone = new ManualResetEvent(false);
// no exceptions
AsyncContinuation asyncContinuation = ex =>
{
lock (exceptions)
{
exceptions.Add(ex);
if (Interlocked.Decrement(ref remaining) == 0)
{
allDone.Set();
}
}
;
};
if (allEventsAtOnce)
{
wrapper.WriteAsyncLogEvents(inputEvents.Select(ev => ev.WithContinuation(asyncContinuation)).ToArray());
}
else
{
for (int i = 0; i < inputEvents.Count; ++i)
{
wrapper.WriteAsyncLogEvent(inputEvents[i].WithContinuation(asyncContinuation));
}
}
allDone.WaitOne();
Assert.Equal(inputEvents.Count, exceptions.Count);
foreach (var e in exceptions)
{
Assert.Null(e);
}
Assert.Equal(inputEvents.Count, myTarget1.WriteCount);
Assert.Equal(inputEvents.Count, myTarget2.WriteCount);
Assert.Equal(inputEvents.Count, myTarget3.WriteCount);
for (int i = 0; i < inputEvents.Count; ++i)
{
Assert.Same(inputEvents[i], myTarget1.WrittenEvents[i]);
Assert.Same(inputEvents[i], myTarget2.WrittenEvents[i]);
Assert.Same(inputEvents[i], myTarget3.WrittenEvents[i]);
}
Exception flushException = null;
var flushHit = new ManualResetEvent(false);
wrapper.Flush(ex =>
{
flushException = ex;
flushHit.Set();
});
flushHit.WaitOne();
if (flushException != null)
{
Assert.True(false, flushException.ToString());
}
Assert.Equal(1, myTarget1.FlushCount);
Assert.Equal(1, myTarget2.FlushCount);
Assert.Equal(1, myTarget3.FlushCount);
}