Пример #1
0
        public static IObservable <TSource> Log <TSource, T>(this IObservable <TSource> source, object host,
                                                             Func <TSource, T> loggedInstance,
                                                             [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int lineNo = 0)
        {
            Guard.NotNull(source);

            return(Observable.Create <TSource>(observer =>
            {
                var meta = new RxLogEntryMeta(host.GetType(), callerMemberName, lineNo);

                var subscription = source.Subscribe(v =>
                {
                    var i = loggedInstance(v);

                    try
                    {
                        RxLog.Log(meta, i);
                    }
                    catch (Exception)
                    {
                        throw;
                    }


                    observer.OnNext(v);
                },
                                                    observer.OnError,
                                                    observer.OnCompleted);


                return new CompositeDisposable(subscription);
            }));
        }
        /// <summary>
        /// Create the default log host using the specified <see cref="RxLoggerConfiguration"/>
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static void SetDefault(this RxLoggerConfiguration configuration)
        {
            var host = configuration.CreateHost();

            var log = new RxLog(host);

            RxLog.SetDefault(log);
        }
Пример #3
0
        /// <summary>
        /// Set the default <see cref="RxLog"/> based upon a specified configuration.
        /// </summary>
        /// <param name="configuration"></param>
        public static void SetDefault(RxLoggerConfiguration configuration)
        {
            Guard.NotNull(configuration);

            var host = configuration.CreateHost();

            RxLog.SetDefault(new RxLog(host));
        }
Пример #4
0
 /// <summary>
 /// Set the default <see cref="RxLog"/> implementation.
 /// </summary>
 /// <param name="rxLog"></param>
 public static void SetDefault(RxLog rxLog)
 {
     if (RxLog.Default != null)
     {
         RxLog.Log(typeof(RxLog), Classified.Error("RxLog already has a default host assigned, request ignored."));
         return;
     }
     RxLog.Default = rxLog;
 }
Пример #5
0
        public static RxLogEntry Log(this object publisher, object instance, [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int lineNo = 0)
        {
            Guard.NotNull(publisher);

            var meta  = RxLog.CreateMeta(publisher.GetType(), callerMemberName, lineNo);
            var entry = new RxLogEntry(meta, instance);

            RxLog.Log(entry);

            return(entry);
        }
Пример #6
0
        public static IObservable <TSource> Trace <TSource>(this IObservable <TSource> source,
                                                            string name = default(string), [CallerMemberName] string callerMemberName = "",
                                                            [CallerLineNumber] int lineNo = 0)
        {
            Guard.NotNull(source);
            // counter used for our 'tick' occurance
            var id = 0;

            return(Observable.Create <TSource>(observer =>
            {
                var id1 = ++id;

                var meta = new RxLogEntryMeta(typeof(ObservableExtensions), callerMemberName, lineNo);

                Action <string, object> trace = (m, v) =>
                {
                    try
                    {
                        RxLog.Log(meta, Classified.Information($"{name} {id1}: {m}({v})"));
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                };

                trace("Subscribe", string.Empty);

                var subscription = source.Subscribe(v =>
                {
                    trace("OnNext", v);
                    observer.OnNext(v);
                },
                                                    e =>
                {
                    trace("OnError", e.Message);
                    observer.OnError(e);
                },
                                                    () =>
                {
                    trace("OnCompleted", "");
                    observer.OnCompleted();
                });


                return new CompositeDisposable(subscription, Disposable.Create(() => trace("Dispose", string.Empty)));
            }));
        }