コード例 #1
0
 private void PushRawToAllActiveSinks(string message, params object[] sinkArgs)
 {
     foreach (var sink in Sinks.Where(x => x.Active))
     {
         sink.Write(message, sinkArgs);
     }
 }
コード例 #2
0
        public void Listen()
        {
            if (Routes.Count() == 0)
            {
                Logger.Info("No routes specified. All emitted values will be passed on to all sinks.");
                Observable
                .Merge(Sources.Select((it) => it.Get()))
                .Catch(Observable.Empty <object>())
                .Subscribe((value) =>
                {
                    Sinks.ForEach((sink) => sink.Consume(value));
                });
                return;
            }

            Logger.Info("Setting up routes...");
            Routes.ForEach(route =>
            {
                var source = Sources.Find(source => source.Id == route.From);
                var sinks  = Sinks.Where(sink => route.To.Contains(sink.Id)).ToList();
                Logger.Info($"Values from {source} will be passed on to {string.Join(", ", sinks.Select(it => it.ToString()))}");

                source
                .Get()
                .Catch(Observable.Empty <object>())
                .Subscribe((value) =>
                {
                    sinks.ForEach((sink) => sink.Consume(value));
                });
            });

            var unconnectedSources = Sources.Where((source) => !Routes.Select((route) => route.From).Contains(source.Id));
            var unconnectedSinks   = Sinks.Where((sink) => !Routes.SelectMany((route) => route.To).Contains(sink.Id));

            if (unconnectedSources.Count() > 0)
            {
                Logger.Warn($"Found {unconnectedSources.Count()} unconnected sources. Emitted values from those will never be processed by any sinks:");
                Logger.Warn(string.Join(", ", unconnectedSources.Select(source => source.ToString())));
            }

            if (unconnectedSinks.Count() > 0)
            {
                Logger.Warn($"Found {unconnectedSinks.Count()} unconnected sinks (not targeted by any route):");
                Logger.Warn(string.Join(", ", unconnectedSinks.Select(sink => sink.ToString())));
                Logger.Warn("Please double check your configuration");
            }
        }
コード例 #3
0
        private void DecorateAndPushToAllActiveSinks(LogLevel logLevel, string message, params object[] sinkArgs)
        {
            foreach (var sink in Sinks.Where(x => x.Active))
            {
                var actualOutput = Template;

                foreach (var kvp in Decorators)
                {
                    actualOutput = actualOutput.Replace(
                        kvp.Key,
                        kvp.Value.Decorate(logLevel, actualOutput, message, sink)
                        );
                }

                sink.Write(logLevel, actualOutput, sinkArgs);
            }
        }