当前位置: 首页>>代码示例>>C#>>正文


C# MyTarget类代码示例

本文整理汇总了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();
        }
开发者ID:304NotModified,项目名称:NLog-1,代码行数:35,代码来源:ImpersonatingTargetWrapperTests.cs

示例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);
        }
开发者ID:Loopt,项目名称:NLog,代码行数:34,代码来源:AutoFlushTargetWrapperTests.cs

示例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);
        }
开发者ID:ExM,项目名称:NLog,代码行数:8,代码来源:TargetTests.cs

示例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);
        }
开发者ID:rameshr,项目名称:NLog,代码行数:9,代码来源:TargetTests.cs

示例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);
 }
开发者ID:RexTremendae,项目名称:NLog,代码行数:9,代码来源:AsyncTargetWrapperTests.cs

示例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));
        }
开发者ID:bryjamus,项目名称:NLog,代码行数:10,代码来源:AsyncTargetWrapperTests.cs

示例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);
        }
开发者ID:MikeFH,项目名称:NLog,代码行数:12,代码来源:TargetTests.cs

示例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);
        }
开发者ID:ExM,项目名称:NLog,代码行数:12,代码来源:TargetTests.cs

示例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);
        }
开发者ID:ExM,项目名称:NLog,代码行数:13,代码来源:TargetTests.cs

示例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);
        }
开发者ID:RexTremendae,项目名称:NLog,代码行数:13,代码来源:AsyncTargetWrapperTests.cs

示例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);
        }
开发者ID:Enzyoh,项目名称:NLog,代码行数:48,代码来源:PostFilteringTargetWrapperTests.cs

示例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);
        }
开发者ID:igalse,项目名称:NLog,代码行数:48,代码来源:RoundRobinGroupTargetTests.cs

示例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);
        }
开发者ID:Enzyoh,项目名称:NLog,代码行数:48,代码来源:RoundRobinGroupTargetTests.cs

示例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);
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:16,代码来源:FallbackGroupTargetTests.cs

示例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);
        }
开发者ID:CharlieBP,项目名称:NLog,代码行数:16,代码来源:FallbackGroupTargetTests.cs


注:本文中的MyTarget类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。