當前位置: 首頁>>代碼示例>>C#>>正文


C# Wrappers.AsyncTargetWrapper類代碼示例

本文整理匯總了C#中NLog.Targets.Wrappers.AsyncTargetWrapper的典型用法代碼示例。如果您正苦於以下問題:C# AsyncTargetWrapper類的具體用法?C# AsyncTargetWrapper怎麽用?C# AsyncTargetWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AsyncTargetWrapper類屬於NLog.Targets.Wrappers命名空間,在下文中一共展示了AsyncTargetWrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InitializeLogging

      public static void InitializeLogging() {
         var config = new LoggingConfiguration();
         Target debuggerTarget = new DebuggerTarget() {
            Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
         };
         Target consoleTarget = new ColoredConsoleTarget() {
            Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
         };

#if !DEBUG
         debuggerTarget = new AsyncTargetWrapper(debuggerTarget);
         consoleTarget = new AsyncTargetWrapper(consoleTarget);
#else
         new AsyncTargetWrapper().Wrap(); // Placeholder for optimizing imports
#endif

         config.AddTarget("debugger", debuggerTarget);
         config.AddTarget("console", consoleTarget);

         var debuggerRule = new LoggingRule("*", LogLevel.Trace, debuggerTarget);
         config.LoggingRules.Add(debuggerRule);

         var consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
         config.LoggingRules.Add(consoleRule);

         LogManager.Configuration = config;
      }
開發者ID:the-dargon-project,項目名稱:Dargon.Zilean,代碼行數:27,代碼來源:ZileanApplicationEgg.cs

示例2: SetupNLog

        private static Logger SetupNLog(NLogConfigurationApi config)
        {
            var logDirectory = string.IsNullOrEmpty(config.LogDirectory) ?
                "${basedir}/Logs" :
                config.LogDirectory;

            var fileTarget = new FileTarget
            {
                Name = "FileTarget",
                Layout = "${message}",
                ConcurrentWrites = false,
                FileName = new SimpleLayout(Path.Combine(logDirectory, "current.log")),
                ArchiveEvery = config.ArchivePeriod,
                ArchiveNumbering = ArchiveNumberingMode.Sequence,
                MaxArchiveFiles = config.MaxArchiveFiles,
                ArchiveFileName = new SimpleLayout(Path.Combine(logDirectory,"archive/{####}.log"))
            };
            var asyncWrapper = new AsyncTargetWrapper(fileTarget)
            {
                Name = "AsyncWrapper"
            };

            var loggingConfiguration = new LoggingConfiguration();
            loggingConfiguration.AddTarget(LoggerName, asyncWrapper);
            loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LevelToNLogLevel(config.MinimumLogLevel), asyncWrapper));

            LogManager.Configuration = loggingConfiguration;

            return LogManager.GetLogger(LoggerName);
        }
開發者ID:oylers,項目名稱:Spiffy,代碼行數:30,代碼來源:NLog.cs

示例3: ConfigureNlog

        public void ConfigureNlog(Logger logger)
        {
            FileTarget target = new FileTarget();

            target.FileName = "${basedir}\\logs\\ICtrl.Log_${date:format=ddMMyyyy}.txt";
            target.KeepFileOpen = false;
            target.Encoding = "windows-1251";
            target.Layout = "${date:format=HH\\:mm\\:ss.fff}|${level:padding=5:uppercase=true}|${message}";

            AsyncTargetWrapper wrapper = new AsyncTargetWrapper();

            wrapper.WrappedTarget = target;
            wrapper.QueueLimit = 5000;
            wrapper.OverflowAction = AsyncTargetWrapperOverflowAction.Block;

            logOn = GetLogLevel();

            switch (logOn)
            {
                case 1:
                    NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Info);
                    break;
                default:
                    NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Off);
                    break;
            }
        }
開發者ID:sokolnikov90,項目名稱:ICTRL,代碼行數:27,代碼來源:Settings.cs

示例4: 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);
        }
開發者ID:MikeFH,項目名稱:NLog,代碼行數:28,代碼來源:AsyncTargetWrapperTests.cs

示例5: AsyncTargetWrapperAsyncTest1

        public void AsyncTargetWrapperAsyncTest1()
        {
            var myTarget = new MyAsyncTarget();
            var targetWrapper = new AsyncTargetWrapper(myTarget);
            ((ISupportsInitialize)targetWrapper).Initialize();
            ((ISupportsInitialize)myTarget).Initialize();
            var logEvent = new LogEventInfo();
            Exception lastException = null;
            var continuationHit = new ManualResetEvent(false);
            AsyncContinuation continuation =
                ex =>
                {
                    lastException = ex;
                    continuationHit.Set();
                };

            targetWrapper.WriteLogEvent(logEvent, continuation);

            continuationHit.WaitOne();
            Assert.IsNull(lastException);
            Assert.AreEqual(1, myTarget.WriteCount);

            continuationHit.Reset();
            targetWrapper.WriteLogEvent(logEvent, continuation);
            continuationHit.WaitOne();
            Assert.IsNull(lastException);
            Assert.AreEqual(2, myTarget.WriteCount);
        }
開發者ID:igalse,項目名稱:NLog,代碼行數:28,代碼來源:AsyncTargetWrapperTests.cs

示例6: 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

示例7: CreateRavenDbTarget

        private static Target CreateRavenDbTarget(IDependencyResolver dependencyResolver, LoggingConfiguration loggingConfiguration)
        {
            var documentStore = (IDocumentStore)dependencyResolver.GetService(typeof(IDocumentStore));
            var ravenDbTarget = new RavenDbTarget(documentStore);
            var asyncWrapper = new AsyncTargetWrapper(ravenDbTarget, 1000, AsyncTargetWrapperOverflowAction.Discard);
            loggingConfiguration.AddTarget("ravenDb", asyncWrapper);

            return asyncWrapper;
        }
開發者ID:jaredrussell,項目名稱:Amikiri,代碼行數:9,代碼來源:NLogConfig.cs

示例8: 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

示例9: 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

示例10: GetTargets

        public IEnumerable<NLog.Targets.Target> GetTargets()
        {
            foreach (var target in this.targetConfigurations)
            {
                var asyncTargetWrapper = new AsyncTargetWrapper()
                {
                    Name = target.Id.ToString(),
                    WrappedTarget = target.Type.GetConstructor(new Type[] { }).Invoke(null) as Target,
                    BatchSize = 1
                };

                yield return asyncTargetWrapper;
            }
        }
開發者ID:jennings,項目名稱:Supervisor,代碼行數:14,代碼來源:ConfigurationBasedNLogTargetFactory.cs

示例11: InitLogger

        protected virtual NLogLogger InitLogger()
        {
            var wrapper = new AsyncTargetWrapper
            {
                Name = typeof (AsyncTargetWrapper).Name,
                QueueLimit = 10000,
                WrappedTarget = LoadTarget(),
                OverflowAction = AsyncTargetWrapperOverflowAction.Grow
            };
            SimpleConfigurator.ConfigureForTargetLogging(wrapper);
            LogManager.Configuration.LoggingRules.ForEachItem(lr => lr.EnableLoggingForLevel(LogLevel.Trace));
            LogManager.ReconfigExistingLoggers();

            return LogManager.GetLogger(LoggerName);
        }
開發者ID:saturn72,項目名稱:Saturn72.Plugins,代碼行數:15,代碼來源:NLogLogWriter.cs

示例12: LogService

        public LogService(Model m)
        {
            LoggingConfiguration config = LogManager.Configuration;
            target = new LogServiceTarget(m.Messages);
            target.Layout =
                "${level}=> ${message} ${exception:format=Message} ${exception:format=Type} ${exception:format=StackTrace}";
            target.Name = "LogService";
            var wrapper = new AsyncTargetWrapper(target);

            config.AddTarget("LogService", wrapper);

            rule = new LoggingRule("*", LogLevel.Trace, target);
            config.LoggingRules.Add(rule);

            LogManager.Configuration = config;
            if (Debugger.IsAttached)
                target.Filter = LogLevel.Debug;
        }
開發者ID:Kayomani,項目名稱:FAP,代碼行數:18,代碼來源:LogService.cs

示例13: Main

    static void Main(string[] args)
    {
        FileTarget target = new FileTarget();
        target.Layout = "${longdate} ${logger} ${message}";
        target.FileName = "${basedir}/logs/logfile.txt";
        target.KeepFileOpen = false;
        target.Encoding = Encoding.UTF8;

        AsyncTargetWrapper wrapper = new AsyncTargetWrapper();
        wrapper.WrappedTarget = target;
        wrapper.QueueLimit = 5000;
        wrapper.OverflowAction = AsyncTargetWrapperOverflowAction.Discard;

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Debug("log message");
    }
開發者ID:ExM,項目名稱:NLog,代碼行數:18,代碼來源:Example.cs

示例14: ConfigureCaptureTarget

        private void ConfigureCaptureTarget()
        {
            captureTarget = new CaptureTarget
                {
                    Layout = "${date}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}"
                };
            captureTarget.LogReceived += target_LogReceived;
            var asyncWrapper = new AsyncTargetWrapper { Name = "CaptureTargetWrapper", WrappedTarget = captureTarget };

            LogManager.Configuration.AddTarget(asyncWrapper.Name, asyncWrapper);
            currentLogLevel = NLog.LogLevel.Info;
            loggingRule = new LoggingRule("*", currentLogLevel, asyncWrapper);
            LogManager.Configuration.LoggingRules.Insert(0, loggingRule);
            LogManager.ReconfigExistingLoggers();
            PropertyChanged += OnPropertyChanged;
#if DEBUG
            DebugEnabled = true;
#endif
        }
開發者ID:ProjectTako,項目名稱:HearthstoneTracker,代碼行數:19,代碼來源:LogFlyoutViewModel.cs

示例15: Initialize

        public void Initialize(string logFilesDirectory)
        {
            var config = new LoggingConfiguration();

            this.logfile = new FileTarget();
            var logfilename = Path.Combine(logFilesDirectory, "${date:format=yyyy-MM-dd}.txt");
            logfile.FileName = logfilename;
            logfile.CreateDirs = true;
            logfile.MaxArchiveFiles = 7;
            logfile.ArchiveEvery = FileArchivePeriod.Day;
            logfile.ConcurrentWrites = true;
            logfile.Layout =
                "${longdate}|${level:uppercase=true}|thread:${threadid}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}";

            var asyncTarget = new AsyncTargetWrapper(logfile)
                                  {
                                      OverflowAction = AsyncTargetWrapperOverflowAction.Grow
                                  };
            config.AddTarget("logfile", asyncTarget);
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, asyncTarget));

//#if DEBUG
//            var tracelogfile = new FileTarget();
//            tracelogfile.FileName = Path.Combine(logFilesDirectory, "${date:format=yyyy-MM-dd}_Trace.txt");
//            tracelogfile.CreateDirs = true;
//            tracelogfile.MaxArchiveFiles = 7;
//            tracelogfile.ArchiveEvery = FileArchivePeriod.Day;
//            tracelogfile.ConcurrentWrites = true;
//            tracelogfile.Layout =
//                "${longdate}|${level:uppercase=true}|thread:${threadid}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}";

//            var asyncTarget2 = new AsyncTargetWrapper(tracelogfile)
//                                   {
//                                       OverflowAction = AsyncTargetWrapperOverflowAction.Grow
//                                   };
//            config.AddTarget("tracelogfile", asyncTarget2);
//            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, asyncTarget2));
//#endif

            LogManager.Configuration = config;
            // Caliburn.Micro.LogManager.GetLog = type => new NLogger(type);
        }
開發者ID:dEMonaRE,項目名稱:HearthstoneTracker,代碼行數:42,代碼來源:AppLogManager.cs


注:本文中的NLog.Targets.Wrappers.AsyncTargetWrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。