Ejemplo n.º 1
0
        /// <summary>
        /// If there is no target in nlog.config definedm a new one is registered with the default maxcount
        /// </summary>
        /// <param name="defaultMaxCount"></param>
        /// <returns></returns>
        public static MyCacheTarget GetInstance(int defaultMaxCount)
        {
            if (LogManager.Configuration == null)
            {
                LogManager.Configuration = new LoggingConfiguration();
            }
            var target = (MyCacheTarget)LogManager.Configuration.AllTargets.FirstOrDefault(t => t is MyCacheTarget);

            if (target == null)
            {
                target = new MyCacheTarget {
                    MaxCount = defaultMaxCount, Name = nameof(MyCacheTarget)
                };
                LogManager.Configuration.AddTarget(target.Name, target);
                LogManager.Configuration.LoggingRules.Insert(0, new LoggingRule("*", LogLevel.FromString("Trace"), target));
                LogManager.ReconfigExistingLoggers();
            }
            return(target);
        }
Ejemplo n.º 2
0
        private void SetupCache()
        {
            var target = MyCacheTarget.GetInstance(1000);

            target.Cache.SubscribeOn(Scheduler.Default).Buffer(TimeSpan.FromMilliseconds(100)).Where(x => x.Any())
            .ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(infos =>
            {
                if (Pause)
                {
                    return;
                }
                foreach (LogEventInfo info in infos)
                {
                    _LogEventInfos.Add(info);
                }
            });    /*
                    * DataTemplate lvItemTemplate = (DataTemplate) FindResource("ButtonTemplate");
                    * target.Cache.SubscribeOn(Scheduler.Default).Buffer(TimeSpan.FromMilliseconds(100)).Where(x => x.Any())
                    * .ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(infos =>
                    * {
                    * foreach (LogEventInfo info in infos)
                    * {
                    *   ListView lv = new ListView();
                    *   lv.ItemTemplate = lvItemTemplate;
                    *   lv.Items.Add(info);
                    *   InlineUIContainer container = new InlineUIContainer(lv);
                    *   var paragraph = new Paragraph(new Run(info.FormattedMessage));
                    *   paragraph.Inlines.Add(container);
                    *   FlowDoc.Blocks.Add(paragraph);
                    *
                    * }
                    * });
                    */
            target.Cache.SubscribeOn(Scheduler.Default).Buffer(TimeSpan.FromMilliseconds(100)).Where(x => x.Any())
            .ObserveOnDispatcher(DispatcherPriority.Background).Subscribe(infos =>
            {
                foreach (LogEventInfo info in infos)
                {
                }
            });
        }