/// <summary> /// Subscribes to an <see cref="IObservable{EventEntry}"/> using a <see cref="ConsoleSink"/>. /// </summary> /// <param name="eventStream">The event stream. Typically this is an instance of <see cref="ObservableEventListener"/>.</param> /// <param name="formatter">The formatter.</param> /// <param name="colorMapper">The color mapper instance.</param> /// <returns>A subscription to the sink that can be disposed to unsubscribe the sink, or to get access to the sink instance.</returns> public static SinkSubscription<ConsoleSink> LogToConsole(this IObservable<EventEntry> eventStream, IEventTextFormatter formatter = null, IConsoleColorMapper colorMapper = null) { var sink = new ConsoleSink(); formatter = formatter ?? new EventTextFormatter(); colorMapper = colorMapper ?? new DefaultConsoleColorMapper(); var subscription = eventStream.SubscribeWithFormatterAndColor(formatter ?? new EventTextFormatter(), colorMapper, sink); return new SinkSubscription<ConsoleSink>(subscription, sink); }
public static Tuple<string, ConsoleColor?> TryFormatAsStringAndColor(this EventEntry entry, IEventTextFormatter formatter, IConsoleColorMapper colorMapper) { Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(formatter, "formatter"); Guard.ArgumentNotNull(colorMapper, "colorMapper"); var message = TryFormatAsString(entry, formatter); if (message != null) { try { var color = colorMapper.Map(entry.Schema.Level); return Tuple.Create(message, color); } catch (Exception e) { SemanticLoggingEventSource.Log.MapEntryLevelToColorFailed((int)entry.Schema.Level, e.ToString()); return Tuple.Create(message, (ConsoleColor?)null); } } return null; }
public static Tuple <string, ConsoleColor?> TryFormatAsStringAndColor(this EventEntry entry, IEventTextFormatter formatter, IConsoleColorMapper colorMapper) { Guard.ArgumentNotNull(entry, "entry"); Guard.ArgumentNotNull(formatter, "formatter"); Guard.ArgumentNotNull(colorMapper, "colorMapper"); var message = TryFormatAsString(entry, formatter); if (message != null) { try { var color = colorMapper.Map(entry.Schema.Level); return(Tuple.Create(message, color)); } catch (Exception e) { SemanticLoggingEventSource.Log.MapEntryLevelToColorFailed((int)entry.Schema.Level, e.ToString()); return(Tuple.Create(message, (ConsoleColor?)null)); } } return(null); }
public static IDisposable SubscribeWithFormatterAndColor(this IObservable <EventEntry> source, IEventTextFormatter formatter, IConsoleColorMapper colorMapper, IObserver <Tuple <string, ConsoleColor?> > sink) { return(source.CreateSubscription(sink, entry => entry.TryFormatAsStringAndColor(formatter, colorMapper))); }
/// <summary> /// Creates an event listener that logs using a <see cref="ConsoleSink"/>. /// </summary> /// <param name="formatter">The formatter.</param> /// <param name="colorMapper">The color mapper instance.</param> /// <returns>An event listener that uses <see cref="ConsoleSink"/> to display events.</returns> public static EventListener CreateListener(IEventTextFormatter formatter = null, IConsoleColorMapper colorMapper = null) { var listener = new ObservableEventListener(); listener.LogToConsole(formatter, colorMapper); return listener; }
protected override void Given() { sut = new DefaultConsoleColorMapper(); results = new Dictionary<EventLevel, ConsoleColor?>(); }
public static IDisposable SubscribeWithFormatterAndColor(this IObservable<EventEntry> source, IEventTextFormatter formatter, IConsoleColorMapper colorMapper, IObserver<Tuple<string, ConsoleColor?>> sink) { return source.CreateSubscription(sink, entry => entry.TryFormatAsStringAndColor(formatter, colorMapper)); }
/// <summary> /// Creates an event listener that logs using a <see cref="ConsoleSink"/>. /// </summary> /// <param name="formatter">The formatter.</param> /// <param name="colorMapper">The color mapper instance.</param> /// <returns>An event listener that uses <see cref="ConsoleSink"/> to display events.</returns> public static EventListener CreateListener(IEventTextFormatter formatter = null, IConsoleColorMapper colorMapper = null) { var listener = new ObservableEventListener(); listener.LogToConsole(formatter, colorMapper); return(listener); }
/// <summary> /// Subscribes to an <see cref="IObservable{EventEntry}"/> using a <see cref="ConsoleSink"/>. /// </summary> /// <param name="eventStream">The event stream. Typically this is an instance of <see cref="ObservableEventListener"/>.</param> /// <param name="formatter">The formatter.</param> /// <param name="colorMapper">The color mapper instance.</param> /// <returns>A subscription to the sink that can be disposed to unsubscribe the sink, or to get access to the sink instance.</returns> public static SinkSubscription <ConsoleSink> LogToConsole(this IObservable <EventEntry> eventStream, IEventTextFormatter formatter = null, IConsoleColorMapper colorMapper = null) { formatter = formatter ?? new EventTextFormatter(); colorMapper = colorMapper ?? new DefaultConsoleColorMapper(); var sink = new ConsoleSink(formatter, colorMapper); var subscription = eventStream.Subscribe(sink); return(new SinkSubscription <ConsoleSink>(subscription, sink)); }
protected override void Given() { Sut = new DefaultConsoleColorMapper(); Results = new Dictionary <EventLevel, ConsoleColor?>(); }
/// <summary> /// Initializes a new instance of the <see cref="ConsoleSink" /> class. /// </summary> public ConsoleSink(IEventTextFormatter formatter, IConsoleColorMapper colorMapper) { this.formatter = formatter; this.colorMapper = colorMapper; }