本文整理汇总了C#中MyTarget类的典型用法代码示例。如果您正苦于以下问题:C# MyTarget类的具体用法?C# MyTarget怎么用?C# MyTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MyTarget类属于命名空间,在下文中一共展示了MyTarget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImpersonatingWrapperTest
public void ImpersonatingWrapperTest()
{
var wrapped = new MyTarget()
{
ExpectedUser = Environment.MachineName + "\\" + NLogTestUser,
};
var wrapper = new ImpersonatingTargetWrapper()
{
UserName = NLogTestUser,
Password = NLogTestUserPassword,
Domain = Environment.MachineName,
WrappedTarget = wrapped,
};
// wrapped.Initialize(null);
wrapper.Initialize(null);
var exceptions = new List<Exception>();
wrapper.WriteAsyncLogEvent(LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add));
Assert.AreEqual(1, exceptions.Count);
wrapper.WriteAsyncLogEvents(
LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add),
LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add),
LogEventInfo.CreateNullEvent().WithContinuation(exceptions.Add));
Assert.AreEqual(4, exceptions.Count);
wrapper.Flush(exceptions.Add);
Assert.AreEqual(5, exceptions.Count);
foreach (var ex in exceptions)
{
Assert.IsNull(ex, Convert.ToString(ex));
}
wrapper.Close();
}
示例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: CloseWithoutInitializeTest
public void CloseWithoutInitializeTest()
{
var target = new MyTarget();
((ISupportsInitialize)target).Close();
// nothing was called
Assert.AreEqual(0, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例4: InitializeTest
public void InitializeTest()
{
var target = new MyTarget();
target.Initialize(null);
// initialize was called once
Assert.AreEqual(1, target.InitializeCount);
Assert.AreEqual(1, target.InitializeCount + target.FlushCount + target.CloseCount + target.WriteCount + target.WriteCount2 + target.WriteCount3);
}
示例5: AsyncTargetWrapperInitTest
public void AsyncTargetWrapperInitTest()
{
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget, 300, AsyncTargetWrapperOverflowAction.Grow);
Assert.Equal(AsyncTargetWrapperOverflowAction.Grow, targetWrapper.OverflowAction);
Assert.Equal(300, targetWrapper.QueueLimit);
Assert.Equal(50, targetWrapper.TimeToSleepBetweenBatches);
Assert.Equal(100, targetWrapper.BatchSize);
}
示例6: MyTarget
public void AsyncTargetWrapperInitTest_WhenTimeToSleepBetweenBatchesIsEqualToZero_ShouldThrowNLogConfigurationException() {
LogManager.ThrowConfigExceptions = true;
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper() {
WrappedTarget = myTarget,
TimeToSleepBetweenBatches = 0,
};
Assert.Throws<NLogConfigurationException>(() => targetWrapper.Initialize(null));
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: AsyncTargetWrapperInitTest2
public void AsyncTargetWrapperInitTest2()
{
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper()
{
WrappedTarget = myTarget,
};
Assert.Equal(AsyncTargetWrapperOverflowAction.Discard, targetWrapper.OverflowAction);
Assert.Equal(10000, targetWrapper.QueueLimit);
Assert.Equal(50, targetWrapper.TimeToSleepBetweenBatches);
Assert.Equal(100, targetWrapper.BatchSize);
}
示例11: 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);
}
示例12: RoundRobinGroupTargetSyncTest1
public void RoundRobinGroupTargetSyncTest1()
{
var myTarget1 = new MyTarget();
var myTarget2 = new MyTarget();
var myTarget3 = new MyTarget();
var wrapper = new RoundRobinGroupTarget()
{
Targets = { myTarget1, myTarget2, myTarget3 },
};
((ISupportsInitialize)myTarget1).Initialize();
((ISupportsInitialize)myTarget2).Initialize();
((ISupportsInitialize)myTarget3).Initialize();
((ISupportsInitialize)wrapper).Initialize();
List<Exception> exceptions = new List<Exception>();
// no exceptions
for (int i = 0; i < 10; ++i)
{
wrapper.WriteLogEvent(LogEventInfo.CreateNullEvent(), exceptions.Add);
}
Assert.AreEqual(10, exceptions.Count);
foreach (var e in exceptions)
{
Assert.IsNull(e);
}
Assert.AreEqual(4, myTarget1.WriteCount);
Assert.AreEqual(3, myTarget2.WriteCount);
Assert.AreEqual(3, myTarget3.WriteCount);
Exception flushException = null;
var flushHit = new ManualResetEvent(false);
wrapper.Flush(ex => { flushException = ex; flushHit.Set(); });
flushHit.WaitOne();
if (flushException != null)
{
Assert.Fail(flushException.ToString());
}
Assert.AreEqual(1, myTarget1.FlushCount);
Assert.AreEqual(1, myTarget2.FlushCount);
Assert.AreEqual(1, myTarget3.FlushCount);
}
示例13: 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);
}
示例14: FirstTargetWorks_Write_AllEventsAreWrittenToFirstTarget
public void FirstTargetWorks_Write_AllEventsAreWrittenToFirstTarget()
{
var myTarget1 = new MyTarget();
var myTarget2 = new MyTarget();
var myTarget3 = new MyTarget();
var wrapper = CreateAndInitializeFallbackGroupTarget(false, myTarget1, myTarget2, myTarget3);
WriteAndAssertNoExceptions(wrapper);
Assert.Equal(10, myTarget1.WriteCount);
Assert.Equal(0, myTarget2.WriteCount);
Assert.Equal(0, myTarget3.WriteCount);
AssertNoFlushException(wrapper);
}
示例15: FirstTwoTargetsFails_Write_ThirdTargetWritesAllEvents
public void FirstTwoTargetsFails_Write_ThirdTargetWritesAllEvents()
{
var myTarget1 = new MyTarget { FailCounter = 1 };
var myTarget2 = new MyTarget { FailCounter = 1 };
var myTarget3 = new MyTarget();
var wrapper = CreateAndInitializeFallbackGroupTarget(false, myTarget1, myTarget2, myTarget3);
WriteAndAssertNoExceptions(wrapper);
Assert.Equal(1, myTarget1.WriteCount);
Assert.Equal(1, myTarget2.WriteCount);
Assert.Equal(10, myTarget3.WriteCount);
AssertNoFlushException(wrapper);
}