/// <summary> /// Creates an event listener that logs using a <see cref="FlatFileSink"/>. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="formatter">The formatter.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> /// <returns>An event listener that uses <see cref="FlatFileSink"/> to log events.</returns> public static EventListener CreateListener(string fileName = null, IEventTextFormatter formatter = null, bool isAsync = false) { var listener = new ObservableEventListener(); listener.LogToFlatFile(fileName, formatter, isAsync); return(listener); }
/// <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> /// Creates an event listener that logs using a <see cref="T:SemanticLogging.SignalR.SignalRSink"/>. /// /// </summary> /// <param name="formatter">The formatter.</param> /// <returns> /// An event listener that uses <see cref="T:SemanticLogging.SignalR.SignalRSink"/> to display events. /// </returns> public static EventListener CreateListener(IEventTextFormatter formatter = null) { ObservableEventListener observableEventListener = new ObservableEventListener(); LogToSignalR((IObservable <EventEntry>)observableEventListener, formatter); return((EventListener)observableEventListener); }
public static SinkSubscription<EmailSink> LogToEmail(this IObservable<EventEntry> eventStream, string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter = null) { var sink = new EmailSink(host, port, recipients, subject, credentials, formatter); var subscription = eventStream.Subscribe(sink); return new SinkSubscription<EmailSink>(subscription, sink); }
public static SinkSubscription<StringSink> LogToCollection( this IObservable<EventEntry> eventStream, Action<string> action, IEventTextFormatter formatter = null) { var sink = new StringSink(action); var subscription = eventStream.Subscribe(sink); return new SinkSubscription<StringSink>(subscription, sink); }
/// <summary> /// Subscribes to an <see cref="T:System.IObservable`1"/> using a <see cref="T:SemanticLogging.SignalR.SignalRSink"/>. /// /// </summary> /// <param name="eventStream">The event stream. Typically this is an instance of <see cref="T:Microsoft.Practices.EnterpriseLibrary.SemanticLogging.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<SignalRSink> LogToSignalR(this IObservable<EventEntry> eventStream, IEventTextFormatter formatter = null) { var sink = new SignalRSink(); formatter = formatter ?? new EventTextFormatter(); EnsureHostConfigured(sink); return new SinkSubscription<SignalRSink>(EventEntryExtensions.SubscribeWithFormatter(eventStream, formatter, sink), sink); }
public static EventListener CreateListener(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter = null) { var listener = new ObservableEventListener(); listener.LogToEmail(host, port, recipients, subject, credentials, formatter); return(listener); }
public static SinkSubscription <EmailSink> LogToEmail( this IObservable <EventEntry> eventStream, string from, string to, string subject, string templateFilePath, IEventTextFormatter formatter = null) { var sink = new EmailSink(from, to, subject, templateFilePath, formatter); var subscription = eventStream.Subscribe(sink); return(new SinkSubscription <EmailSink>(subscription, sink)); }
public static SinkSubscription <StringSink> LogToCollection( this IObservable <EventEntry> eventStream, Action <string> action, IEventTextFormatter formatter = null) { var sink = new StringSink(action); var subscription = eventStream.Subscribe(sink); return(new SinkSubscription <StringSink>(subscription, sink)); }
/// <summary> /// Formats the event as a string. /// </summary> /// <param name="snapshot">The partition snapshot to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted snapshot.</returns> public static string WriteEvent(this IEventTextFormatter formatter, PartitionSnapshot snapshot) { Guard.ArgumentNotNull(formatter, "formatter"); using (var writer = new StringWriter(CultureInfo.CurrentCulture)) { formatter.WriteEvent(snapshot, writer); return(writer.ToString()); } }
public InMemoryEventListener(IEventTextFormatter formatter = null) { this.Formatter = formatter ?? new EventTextFormatter(verbosityThreshold: EventLevel.LogAlways); this.memory = new MemoryStream(); this.writer = new StreamWriter(this.memory) { AutoFlush = false }; this.waitOnAsync = new ManualResetEventSlim(); }
public static SinkSubscription <EmailSink> LogToEmail( this IObservable <EventEntry> eventStream, string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter = null) { var sink = new EmailSink(host, port, recipients, subject, credentials, formatter); var subscription = eventStream.Subscribe(sink); return(new SinkSubscription <EmailSink>(subscription, sink)); }
/// <summary> /// Formats the event as a string. /// </summary> /// <param name="entry">The entry to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted entry.</returns> public static string WriteEvent(this IEventTextFormatter formatter, EventEntry entry) { Guard.ArgumentNotNull(formatter, "formatter"); using (var writer = new StringWriter(CultureInfo.CurrentCulture)) { formatter.WriteEvent(entry, writer); return(writer.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="RollingFlatFileSink"/> class with the specified values. /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="rollSizeKB">The maximum file size (KB) before rolling.</param> /// <param name="timestampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the roll file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file to be rolled.</param> /// <param name="maxArchivedFiles">The maximum number of archived files to keep.</param> /// <param name="formatter">The event entry formatter.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> public RollingFlatFileSink(string fileName, int rollSizeKB, string timestampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, int maxArchivedFiles, IEventTextFormatter formatter, bool isAsync) { Guard.ArgumentNotNull(formatter, "formatter"); this.file = FileUtil.ProcessFileNameForLogging(fileName); this.formatter = formatter; if (rollInterval == RollInterval.None) { if (!string.IsNullOrWhiteSpace(timestampPattern)) { Guard.ValidateTimestampPattern(timestampPattern, "timestampPattern"); } } else { Guard.ValidateTimestampPattern(timestampPattern, "timestampPattern"); } this.writer = new TallyKeepingFileStreamWriter(this.file.Open(FileMode.Append, FileAccess.Write, FileShare.Read)); this.rollSizeInBytes = rollSizeKB * 1024L; this.timestampPattern = timestampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.maxArchivedFiles = maxArchivedFiles; this.isAsync = isAsync; this.rollingHelper = new StreamWriterRollingHelper(this); if (rollInterval == RollInterval.Midnight && !isAsync) { var now = this.rollingHelper.DateTimeProvider.CurrentDateTime; var midnight = now.AddDays(1).Date; var callback = new TimerCallback(delegate { lock (this.lockObject) { this.rollingHelper.RollIfNecessary(); } }); this.timer = new Timer(callback, null, midnight.Subtract(now), TimeSpan.FromDays(1)); } this.flushSource.SetResult(true); if (isAsync) { this.cancellationTokenSource = new CancellationTokenSource(); this.pendingEntries = new BlockingCollection <EventEntry>(); this.asyncProcessorTask = Task.Factory.StartNew(this.WriteEntries, TaskCreationOptions.LongRunning); } }
public EmailSink(string host, int port, string recipients, string subject, string username, string password, bool ssl, string from, IEventTextFormatter formatter) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = GuardPort(port); this.credentials = new NetworkCredential(username, password); this.sender = new MailAddress(from); this.recipients = GuardRecipients(recipients); this.subject = subject; this.ssl = ssl; }
/// <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 EmailSink(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = port; this.credentials = CredentialManager.GetCredentials(credentials); this.sender = new MailAddress(this.credentials.UserName); this.recipients.Add(recipients); this.subject = subject ?? DefaultSubject; }
public EmailSink(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = GuardPort(port); this.credentials = new NetworkCredential("*****@*****.**", "password");//CredentialManager.GetCredentials(credentials); this.sender = new MailAddress(this.credentials.UserName); this.recipients.Add(GuardRecipients(recipients)); this.subject = subject ?? DefaultSubject; }
public MockFlatFileSink2(string fileName, string header, IEventTextFormatter formatter = null) { FileUtil.ValidFile(fileName); this.Formatter = formatter ?? new EventTextFormatter(header: header, verbosityThreshold: EventLevel.LogAlways); var file = FileUtil.ProcessFileNameForLogging(fileName); this.writer = new StreamWriter(file.Open(FileMode.Append, FileAccess.Write, FileShare.Read)); this.flushSource.SetResult(true); }
public EmailSink(string from, string to, string subject, string templateFilePath, IEventTextFormatter formatter) { Guard.ArgumentNotNullOrEmpty(from, "from"); Guard.ArgumentNotNullOrEmpty(to, "to"); Guard.ArgumentNotNullOrEmpty(templateFilePath, "templateFilePath"); this.formatter = formatter ?? new HtmlEventTextFormatter(); this.from = from; this.to = to; this.subject = subject ?? DefaultSubject; this.templateFilePath = templateFilePath; }
/// <summary> /// Formats an <see cref="EventEntry"/> as a string using an <see cref="IEventTextFormatter"/>. /// </summary> /// <param name="entry">The entry to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted entry, or <see langword="null"/> if an exception is thrown by the <paramref name="formatter"/>.</returns> public static string TryFormatAsString(this EventEntry entry, IEventTextFormatter formatter) { try { return(formatter.WriteEvent(entry)); } catch (Exception e) { SemanticLoggingEventSource.Log.FormatEntryAsStringFailed(e.ToString()); } return(null); }
/// <summary> /// Formats an <see cref="PartitionSnapshot" /> as a string using an <see cref="IEventTextFormatter" />. /// </summary> /// <param name="snapshot">The snapshot to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted snapshot, or <see langword="null" /> if an exception is thrown by the <paramref name="formatter" />.</returns> public static string TryFormatAsString(this PartitionSnapshot snapshot, IEventTextFormatter formatter) { try { return formatter.WriteEvent(snapshot); } catch (Exception e) { //SemanticLoggingEventSource.Log.FormatEntryAsStringFailed(e.ToString()); } return null; }
/// <summary> /// Formats an <see cref="PartitionSnapshot" /> as a string using an <see cref="IEventTextFormatter" />. /// </summary> /// <param name="snapshot">The snapshot to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted snapshot, or <see langword="null" /> if an exception is thrown by the <paramref name="formatter" />.</returns> public static string TryFormatAsString(this PartitionSnapshot snapshot, IEventTextFormatter formatter) { try { return(formatter.WriteEvent(snapshot)); } catch (Exception e) { //SemanticLoggingEventSource.Log.FormatEntryAsStringFailed(e.ToString()); } return(null); }
/// <summary> /// Subscribes to an <see cref="IObservable{EventEntry}"/> using a <see cref="FlatFileSink"/>. /// </summary> /// <param name="eventStream">The event stream. Typically this is an instance of <see cref="ObservableEventListener"/>.</param> /// <param name="fileName">Name of the file.</param> /// <param name="formatter">The formatter.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> /// <returns>A subscription to the sink that can be disposed to unsubscribe the sink and dispose it, or to get access to the sink instance.</returns> public static SinkSubscription<FlatFileSink> LogToFlatFile(this IObservable<EventEntry> eventStream, string fileName = null, IEventTextFormatter formatter = null, bool isAsync = false) { if (string.IsNullOrEmpty(fileName)) { fileName = FileUtil.CreateRandomFileName(); } var sink = new FlatFileSink(fileName, isAsync); var subscription = eventStream.SubscribeWithFormatter(formatter ?? new EventTextFormatter(), sink); return new SinkSubscription<FlatFileSink>(subscription, sink); }
/// <summary> /// Subscribes to an <see cref="IObservable{EventEntry}"/> using a <see cref="RollingFlatFileSink"/>. /// </summary> /// <param name="eventStream">The event stream. Typically this is an instance of <see cref="ObservableEventListener"/>.</param> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="rollSizeKB">The maximum file size (KB) before rolling.</param> /// <param name="timestampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the roll file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file to be rolled.</param> /// <param name="formatter">The formatter.</param> /// <param name="maxArchivedFiles">The maximum number of archived files to keep.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> /// <returns>A subscription to the sink that can be disposed to unsubscribe the sink and dispose it, or to get access to the sink instance.</returns> public static SinkSubscription<RollingFlatFileSink> LogToRollingFlatFile(this IObservable<EventEntry> eventStream, string fileName, int rollSizeKB, string timestampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, IEventTextFormatter formatter = null, int maxArchivedFiles = 0, bool isAsync = false) { if (string.IsNullOrWhiteSpace(fileName)) { fileName = FileUtil.CreateRandomFileName(); } var sink = new RollingFlatFileSink(fileName, rollSizeKB, timestampPattern, rollFileExistsBehavior, rollInterval, maxArchivedFiles, isAsync); var subscription = eventStream.SubscribeWithFormatter(formatter ?? new EventTextFormatter(), sink); return new SinkSubscription<RollingFlatFileSink>(subscription, sink); }
/// <summary> /// Formats an <see cref="EventEntry"/> as a string using an <see cref="IEventTextFormatter"/>. /// </summary> /// <param name="entry">The entry to format.</param> /// <param name="formatter">The formatter to use.</param> /// <returns>A formatted entry, or <see langword="null"/> if an exception is thrown by the <paramref name="formatter"/>.</returns> public static string TryFormatAsString(this EventEntry entry, IEventTextFormatter formatter) { try { return formatter.WriteEvent(entry); } catch (Exception e) { SemanticLoggingEventSource.Log.FormatEntryAsStringFailed(e.ToString()); } return null; }
public ElasticSearchSink(string connectionString, string index, bool appendDate, string dateFormat, IEventTextFormatter formatter) { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentException("A ConnectionString must be specified", "connectionString"); } _connectionString = connectionString; _index = string.IsNullOrWhiteSpace(index) ? DefaultIndex : index.ToLower(); _appendDate = appendDate; _dateFormat = string.IsNullOrWhiteSpace(dateFormat) ? DefaultDateFormat : dateFormat; _formatter = formatter ?? new EventTextFormatter(); }
/// <summary> /// HttpEventCollectorEventSink c-or. Instantiates HttpEventCollectorEventSink /// when retriesOnError parameter is specified. /// </summary> /// <param name="uri">Splunk server uri, for example https://localhost:8088.</param> /// <param name="token">HTTP event collector authorization token.</param> /// <param name="formatter">Event formatter converting EventEntry instance into a string.</param> /// <param name="retriesOnError">Number of retries when network problem is detected</param> /// <param name="metadata">Logger metadata.</param> /// <param name="sequentialMode">Send mode of the events.</param> /// <param name="batchInterval">Batch interval in milliseconds.</param> /// <param name="batchSizeBytes">Batch max size.</param> /// <param name="batchSizeCount">MNax number of individual events in batch.</param> public HttpEventCollectorSink( Uri uri, string token, IEventTextFormatter formatter, int retriesOnError, HttpEventCollectorEventInfo.Metadata metadata = null, HttpEventCollectorSender.SendMode sendMode = HttpEventCollectorSender.SendMode.Sequential, int batchInterval = HttpEventCollectorSender.DefaultBatchInterval, int batchSizeBytes = HttpEventCollectorSender.DefaultBatchSize, int batchSizeCount = HttpEventCollectorSender.DefaultBatchCount) : this(uri, token, formatter, metadata, sendMode, batchInterval, batchSizeBytes, batchSizeCount, (new HttpEventCollectorResendMiddleware(retriesOnError)).Plugin) { }
public EmailSink(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter, IOptions <Settings_Email> optionsAccessor) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = GuardPort(port); _settings = optionsAccessor.Value; // reads appsettings.json this.sender = new MailAddress(_settings.UserName); // see http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/09/06/accessing-web-config-file-smtp-mail-settings-programmatically.aspx this.recipients.Add(GuardRecipients(recipients)); this.subject = subject ?? DefaultSubject; }
public EmailSink(string host, int port, string recipients, string subject, string credentials, IEventTextFormatter formatter) { this.formatter = formatter ?? new EventTextFormatter(); this.host = host; this.port = GuardPort(port); //Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); Configuration config = WebConfigurationManager.OpenWebConfiguration("/TrackRE"); MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings"); this.sender = new MailAddress(settings.Smtp.Network.UserName); // see http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/09/06/accessing-web-config-file-smtp-mail-settings-programmatically.aspx this.recipients.Add(GuardRecipients(recipients)); this.subject = subject ?? DefaultSubject; }
/// <summary> /// HttpEventCollectorEventSink c-or with middleware parameter. /// </summary> /// <param name="uri">Splunk server uri, for example https://localhost:8088.</param> /// <param name="token">HTTP event collector authorization token.</param> /// <param name="formatter">Event formatter converting EventEntry instance into a string.</param> /// <param name="metadata">Logger metadata.</param> /// <param name="sendMode">Send mode of the events.</param> /// <param name="batchInterval">Batch interval in milliseconds.</param> /// <param name="batchSizeBytes">Batch max size.</param> /// <param name="batchSizeCount">MNax number of individual events in batch.</param> /// <param name="middleware"> /// HTTP client middleware. This allows to plug an HttpClient handler that /// intercepts logging HTTP traffic. /// </param> public HttpEventCollectorSink( Uri uri, string token, IEventTextFormatter formatter, HttpEventCollectorEventInfo.Metadata metadata = null, HttpEventCollectorSender.SendMode sendMode = HttpEventCollectorSender.SendMode.Sequential, int batchInterval = HttpEventCollectorSender.DefaultBatchInterval, int batchSizeBytes = HttpEventCollectorSender.DefaultBatchSize, int batchSizeCount = HttpEventCollectorSender.DefaultBatchCount, HttpEventCollectorSender.HttpEventCollectorMiddleware middleware = null) { this.formatter = formatter; sender = new HttpEventCollectorSender( uri, token, metadata, sendMode, batchInterval, batchSizeBytes, batchSizeCount, middleware); }
/// <summary> /// Initializes a new instance of the <see cref="FlatFileSink" /> class. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="formatter">The formatter for entries</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> public FlatFileSink(string fileName, IEventTextFormatter formatter, bool isAsync) { Guard.ArgumentNotNull(formatter, "formatter"); var file = FileUtil.ProcessFileNameForLogging(fileName); this.formatter = formatter; this.writer = new StreamWriter(file.Open(FileMode.Append, FileAccess.Write, FileShare.Read)); this.isAsync = isAsync; this.flushSource.SetResult(true); if (isAsync) { this.cancellationTokenSource = new CancellationTokenSource(); this.pendingEntries = new BlockingCollection <EventEntry>(); this.asyncProcessorTask = Task.Factory.StartNew((Action)this.WriteEntries, TaskCreationOptions.LongRunning); } }
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> /// Subscribes an <see cref="IObserver{String}"/> sink by doing a straight projection of a sequence of <see cref="EventEntry"/> and applying /// a format using a <see cref="IEventTextFormatter"/> instance to convert it to a <see cref="string"/> message. /// </summary> /// <param name="source">The original stream of events.</param> /// <param name="formatter">The formatter to use.</param> /// <param name="sink">The underlying sink.</param> /// <returns>A subscription token to unsubscribe to the event stream.</returns> /// <remarks>When using Reactive Extensions (Rx), this is equivalent to doing a Select statement on the <paramref name="source"/> to convert it to <see cref="IObservable{String}"/> and then /// calling Subscribe on it. /// </remarks> public static IDisposable SubscribeWithFormatter(this IObservable <EventEntry> source, IEventTextFormatter formatter, IObserver <string> sink) { return(source.CreateSubscription(sink, entry => entry.TryFormatAsString(formatter))); }
public static SinkSubscription <XUnitOutputSink> LogToTestOutput(this IObservable <EventEntry> eventStream, ITestOutputHelper output, IEventTextFormatter formatter = null) { formatter = formatter ?? new EventTextFormatter(); var sink = new XUnitOutputSink(output, formatter); return(new SinkSubscription <XUnitOutputSink>(eventStream.Subscribe(sink), sink)); }
public XUnitOutputSink(ITestOutputHelper output, IEventTextFormatter formatter) { this.output = output; this.formatter = formatter; }
/// <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> /// Creates an event listener that logs using a <see cref="T:SemanticLogging.SignalR.SignalRSink"/>. /// /// </summary> /// <param name="formatter">The formatter.</param> /// <returns> /// An event listener that uses <see cref="T:SemanticLogging.SignalR.SignalRSink"/> to display events. /// </returns> public static EventListener CreateListener(IEventTextFormatter formatter = null ) { ObservableEventListener observableEventListener = new ObservableEventListener(); LogToSignalR((IObservable<EventEntry>)observableEventListener, formatter); return (EventListener)observableEventListener; }
public StringCollectionEventListener(IEventTextFormatter formatter = null) { this.formatter = formatter ?? new JsonEventTextFormatter(); EventsWritten = new List <string>(); }
/// <summary> /// Creates an event listener that logs using a <see cref="FlatFileSink"/>. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="formatter">The formatter.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> /// <returns>An event listener that uses <see cref="FlatFileSink"/> to log events.</returns> public static EventListener CreateListener(string fileName = null, IEventTextFormatter formatter = null, bool isAsync = false) { var listener = new ObservableEventListener(); listener.LogToFlatFile(fileName, formatter, isAsync); return listener; }
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> /// Subscribes an <see cref="IObserver{String}"/> sink by doing a straight projection of a sequence of <see cref="EventEntry"/> and applying /// a format using a <see cref="IEventTextFormatter"/> instance to convert it to a <see cref="string"/> message. /// </summary> /// <param name="source">The original stream of events.</param> /// <param name="formatter">The formatter to use.</param> /// <param name="sink">The underlying sink.</param> /// <returns>A subscription token to unsubscribe to the event stream.</returns> /// <remarks>When using Reactive Extensions (Rx), this is equivalent to doing a Select statement on the <paramref name="source"/> to convert it to <see cref="IObservable{String}"/> and then /// calling Subscribe on it. /// </remarks> public static IDisposable SubscribeWithFormatter(this IObservable<EventEntry> source, IEventTextFormatter formatter, IObserver<string> sink) { return source.CreateSubscription(sink, entry => TryFormatAsString(entry, formatter)); }
public InMemoryEventListener(IEventTextFormatter formatter) { this.Formatter = formatter; this.Stream = new MemoryStream(); this.writer = new StreamWriter(this.Stream); }
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); }
/// <summary> /// Creates an event listener that logs using a <see cref="RollingFlatFileSink"/>. /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="rollSizeKB">The maximum file size (KB) before rolling.</param> /// <param name="timestampPattern">The date format that will be appended to the new roll file.</param> /// <param name="rollFileExistsBehavior">Expected behavior that will be used when the roll file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file to be rolled.</param> /// <param name="formatter">The formatter.</param> /// <param name="maxArchivedFiles">The maximum number of archived files to keep.</param> /// <param name="isAsync">Specifies if the writing should be done asynchronously, or synchronously with a blocking call.</param> /// <returns>An event listener that uses <see cref="RollingFlatFileSink"/> to log events.</returns> public static EventListener CreateListener(string fileName, int rollSizeKB, string timestampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, IEventTextFormatter formatter = null, int maxArchivedFiles = 0, bool isAsync = false) { var listener = new ObservableEventListener(); listener.LogToRollingFlatFile(fileName, rollSizeKB, timestampPattern, rollFileExistsBehavior, rollInterval, formatter, maxArchivedFiles, isAsync); return listener; }