/// <summary> /// Initializes a new instance of the <see cref="RollingFlatFileTraceListener"/> class. /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium 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 rolles.</param> /// <param name="maxArchivedFiles">The maximum number of archived files to keep.</param> public RollingFlatFileTraceListener(string fileName, string header = DefaultSeparator, string footer = DefaultSeparator, ILogFormatter formatter = null, int rollSizeKB = 0, string timeStampPattern = "yyyy-MM-dd", RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Overwrite, RollInterval rollInterval = RollInterval.None, int maxArchivedFiles = 0) : base(fileName, header, footer, formatter) { Guard.ArgumentNotNullOrEmpty(fileName, "fileName"); this.rollSizeInBytes = rollSizeKB * 1024; this.timeStampPattern = timeStampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.maxArchivedFiles = maxArchivedFiles; this.rollingHelper = new StreamWriterRollingHelper(this); if (rollInterval == RollInterval.Midnight) { var now = this.rollingHelper.DateTimeProvider.CurrentDateTime; var midnight = now.AddDays(1).Date; this.timer = new Timer((o) => this.rollingHelper.RollIfNecessary(), null, midnight.Subtract(now), TimeSpan.FromDays(1)); } }
public void CanDeserializeSerializedConfiguration() { string name = "some name"; string fileName = "some filename"; string timesTampPattern = "yyyy-MM-dd"; int rollSizeKB = 10; RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Increment; RollInterval rollInterval = RollInterval.Hour; TraceOptions traceOptions = TraceOptions.LogicalOperationStack; string SimpleTextFormat = "SimpleTextFormat"; string header = "header"; string footer = "footer"; int maxArchivedFiles = 10; RollingFlatFileTraceListenerData data = new RollingFlatFileTraceListenerData( name, fileName, header, footer, rollSizeKB, timesTampPattern, rollFileExistsBehavior, rollInterval, traceOptions, SimpleTextFormat, SourceLevels.Critical); data.TraceOutputOptions = traceOptions; data.MaxArchivedFiles = maxArchivedFiles; LoggingSettings settings = new LoggingSettings(); settings.TraceListeners.Add(data); IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections[LoggingSettings.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName); Assert.AreEqual(1, roSettigs.TraceListeners.Count); Assert.IsNotNull(roSettigs.TraceListeners.Get(name)); Assert.AreEqual(TraceOptions.LogicalOperationStack, roSettigs.TraceListeners.Get(name).TraceOutputOptions); Assert.AreEqual(SourceLevels.Critical, roSettigs.TraceListeners.Get(name).Filter); Assert.AreSame(typeof(RollingFlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).GetType()); Assert.AreSame(typeof(RollingFlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType); Assert.AreSame(typeof(RollingFlatFileTraceListener), roSettigs.TraceListeners.Get(name).Type); Assert.AreEqual(fileName, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).FileName); Assert.AreEqual(timesTampPattern, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).TimeStampPattern); Assert.AreEqual(rollSizeKB, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollSizeKB); Assert.AreEqual(rollFileExistsBehavior, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollFileExistsBehavior); Assert.AreEqual(rollInterval, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollInterval); Assert.AreEqual("SimpleTextFormat", ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter); Assert.AreEqual(header, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Header); Assert.AreEqual(footer, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Footer); Assert.AreEqual(maxArchivedFiles, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).MaxArchivedFiles); }
/// <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); } }
/// <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); }
public FlatFileListener(string fileName, string header = "----------------------------------", string footer = "----------------------------------", ILogFormatter formatter = null, int rollSizeKb = 20000, string timeStampPattern = "yyyy-MM-dd hh:mm:ss", RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Increment, RollInterval rollInterval = RollInterval.Day, int maxArchivedFiles = 0) : base(Path.Combine(ResolveLogPath(), fileName), header, footer, formatter, rollSizeKb, timeStampPattern, rollFileExistsBehavior, rollInterval, maxArchivedFiles) { }
/// <summary> /// Initializes a new instance of the <see cref="RollingXmlTraceListenerData"/> class. /// </summary> /// <param name="name">The name for the configuration object.</param> /// <param name="traceOutputOptions">The trace options.</param> /// <param name="fileName"></param> /// <param name="rollSizeKB"></param> /// <param name="timeStampPattern"></param> /// <param name="rollFileExistsBehavior"></param> /// <param name="rollInterval"></param> public RollingXmlTraceListenerData(string name, string fileName, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, TraceOptions traceOutputOptions) : base(name, typeof(RollingXmlTraceListener), traceOutputOptions) { FileName = fileName; RollSizeKB = rollSizeKB; RollFileExistsBehavior = rollFileExistsBehavior; RollInterval = rollInterval; TimeStampPattern = timeStampPattern; }
public RollingXmlTraceListener( string fileName, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, int maxArchivedFiles) : base(fileName) { this.rollSizeInBytes = rollSizeKB * 1024; this.timeStampPattern = timeStampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.maxArchivedFiles = maxArchivedFiles; this.rollingHelper = new StreamWriterRollingHelper(this); }
/// <summary> /// Initializes a new instance of <see cref="RollingFlatFileTraceListener"/> /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium 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 rool file has to be created.</param> /// <param name="rollInterval">The time interval that makes the file rolles.</param> public RollingFlatFileTraceListener(string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : base(fileName, header, footer, formatter) { this.rollSizeInBytes = rollSizeKB * 1024; this.timeStampPattern = timeStampPattern; this.rollFileExistsBehavior = rollFileExistsBehavior; this.rollInterval = rollInterval; this.rollingHelper = new StreamWriterRollingHelper(this); }
/// <summary> /// Initialize a new instance of the <see cref="RollingTraceListenerNode"/> class with a <see cref="RollingFlatFileTraceListenerData"/> instance. /// </summary> /// <param name="data">A <see cref="RollingFlatFileTraceListenerData"/> instance</param> public RollingTraceListenerNode(Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData data) { if (null == data) { throw new ArgumentNullException("data"); } Rename(data.Name); this.fileName = data.FileName; this.rollSizeKB = data.RollSizeKB; this.timeStampPattern = data.TimeStampPattern; this.rollFileExistsBehavior = data.RollFileExistsBehavior; this.rollInterval = data.RollInterval; this.TraceOutputOptions = data.TraceOutputOptions; this.formatterName = data.Formatter; this.header = data.Header; this.footer = data.Footer; }
/// <summary> /// Initializes a new instance of <see cref="RollingFlatFileTraceListener"/> /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium 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 rolles.</param> public RollingFlatFileTraceListener( string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : this(fileName, header, footer, formatter, rollSizeKB, timeStampPattern, rollFileExistsBehavior, rollInterval, 0) { }
/// <summary> /// Initializes a new instance of the <see cref="RollingFlatFileTraceListenerData"/> class. /// </summary> /// <param name="name">The name for the configuration object.</param> /// <param name="traceOutputOptions">The trace options.</param> /// <param name="fileName"></param> /// <param name="footer"></param> /// <param name="header"></param> /// <param name="rollSizeKB"></param> /// <param name="timeStampPattern"></param> /// <param name="rollFileExistsBehavior"></param> /// <param name="rollInterval"></param> /// <param name="formatter"></param> public RollingFlatFileTraceListenerData(string name, string fileName, string header, string footer, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval, TraceOptions traceOutputOptions, string formatter) : base(name, typeof(RollingFlatFileTraceListener), traceOutputOptions) { FileName = fileName; Header = header; Footer = footer; RollSizeKB = rollSizeKB; RollFileExistsBehavior = rollFileExistsBehavior; RollInterval = rollInterval; TimeStampPattern = timeStampPattern; Formatter = formatter; }
/// <summary> /// Initializes a new instance of <see cref="RollingFlatFileTraceListener"/> /// </summary> /// <param name="fileName">The filename where the entries will be logged.</param> /// <param name="header">The header to add before logging an entry.</param> /// <param name="footer">The footer to add after logging an entry.</param> /// <param name="formatter">The formatter.</param> /// <param name="rollSizeKB">The maxium 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 rolles.</param> public RollingFlatFileTraceListener( string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : this( fileName, header, footer, formatter, rollSizeKB, timeStampPattern, rollFileExistsBehavior, rollInterval, 0) { }
public IObserver <EventEntry> CreateSink(XElement element) { Guard.ArgumentNotNull(element, "element"); int rollSizeKB = (int?)element.Attribute("rollSizeKB") ?? default(int); RollFileExistsBehavior rollFileExistsBehavior = (RollFileExistsBehavior)Enum.Parse(typeof(RollFileExistsBehavior), (string)element.Attribute("rollFileExistsBehavior") ?? default(RollFileExistsBehavior).ToString()); RollInterval rollInterval = (RollInterval)Enum.Parse(typeof(RollInterval), (string)element.Attribute("rollInterval") ?? default(RollInterval).ToString()); int maxArchivedFiles = (int?)element.Attribute("maxArchivedFiles") ?? default(int); var subject = new EventEntrySubject(); subject.LogToRollingFlatFile( (string)element.Attribute("fileName"), rollSizeKB, (string)element.Attribute("timeStampPattern"), rollFileExistsBehavior, rollInterval, FormatterElementFactory.Get(element), maxArchivedFiles); return(subject); }
public void RollingFlatFileTraceListenerNodeDataTest() { string name = "some name"; string fileName = "some filename"; string timesTampPattern = "yyyy-MM-dd"; int rollSizeKB = 10; RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Increment; RollInterval rollInterval = RollInterval.Hour; TraceOptions traceOutputOptions = TraceOptions.Callstack; SourceLevels filter = SourceLevels.Critical; string header = "header"; string footer = "footer"; RollingFlatFileTraceListenerData rollingFlatFileTraceListenerData = new RollingFlatFileTraceListenerData(); rollingFlatFileTraceListenerData.Name = name; rollingFlatFileTraceListenerData.FileName = fileName; rollingFlatFileTraceListenerData.TimeStampPattern = timesTampPattern; rollingFlatFileTraceListenerData.RollSizeKB = rollSizeKB; rollingFlatFileTraceListenerData.RollFileExistsBehavior = rollFileExistsBehavior; rollingFlatFileTraceListenerData.RollInterval = rollInterval; rollingFlatFileTraceListenerData.TraceOutputOptions = traceOutputOptions; rollingFlatFileTraceListenerData.Filter = filter; rollingFlatFileTraceListenerData.Header = header; rollingFlatFileTraceListenerData.Footer = footer; RollingTraceListenerNode rollingFlatFileTraceListenerNode = new RollingTraceListenerNode(rollingFlatFileTraceListenerData); ApplicationNode.AddNode(rollingFlatFileTraceListenerNode); Assert.AreEqual(name, rollingFlatFileTraceListenerNode.Name); Assert.AreEqual(fileName, rollingFlatFileTraceListenerNode.FileName); Assert.AreEqual(timesTampPattern, rollingFlatFileTraceListenerNode.TimeStampPattern); Assert.AreEqual(rollSizeKB, rollingFlatFileTraceListenerNode.RollSizeKB); Assert.AreEqual(rollFileExistsBehavior, rollingFlatFileTraceListenerNode.RollFileExistsBehavior); Assert.AreEqual(rollInterval, rollingFlatFileTraceListenerNode.RollInterval); Assert.AreEqual(traceOutputOptions, rollingFlatFileTraceListenerNode.TraceOutputOptions); Assert.AreEqual(filter, rollingFlatFileTraceListenerNode.Filter); Assert.AreEqual(header, rollingFlatFileTraceListenerNode.Header); Assert.AreEqual(footer, rollingFlatFileTraceListenerNode.Footer); }
public void EntryIsWrittenWhenConfiguringLoggingWithRollingFile() { const string FilePath = "sample.log"; const string ListenerName = "Rolling File Listener"; const string FormatterName = "Text Formatter"; const string Template = "My template"; const string Footer = "Footer"; const string Header = "Header"; const int RollAfterSize = 150; const int NumberFiles = 5; const string TimeStampPattern = "yyyymmdd"; RollInterval rollInterval = RollInterval.Day; RollFileExistsBehavior behavior = RollFileExistsBehavior.Increment; configurationStart.LogToCategoryNamed(CategoryName) .WithOptions .DoNotAutoFlushEntries() .SetAsDefaultCategory() .ToSourceLevels(SourceLevels.ActivityTracing) .SendTo .RollingFile(ListenerName) .RollEvery(rollInterval) .RollAfterSize(RollAfterSize) .CleanUpArchivedFilesWhenMoreThan(NumberFiles) .WhenRollFileExists(behavior) .UseTimeStampPattern(TimeStampPattern) .ToFile(FilePath) .WithFooter(Footer) .WithHeader(Header) .WithTraceOptions(TraceOptions.None) .FormatWith(new FormatterBuilder() .TextFormatterNamed(FormatterName) .UsingTemplate(Template)); LoggingSettings settings = GetLoggingSettings(); Assert.IsNotNull(settings); Assert.AreEqual(CategoryName, settings.DefaultCategory); Assert.AreEqual(1, settings.TraceSources.Count); var traceSource = settings.TraceSources.Get(0); Assert.IsFalse(traceSource.AutoFlush); Assert.AreEqual(SourceLevels.ActivityTracing, traceSource.DefaultLevel); Assert.AreEqual(ListenerName, traceSource.TraceListeners.Get(0).Name); Assert.AreEqual(1, settings.TraceListeners.Count); var rollingFile = settings.TraceListeners.Get(0) as RollingFlatFileTraceListenerData; Assert.IsNotNull(rollingFile); Assert.AreEqual(ListenerName, rollingFile.Name); Assert.AreEqual(behavior, rollingFile.RollFileExistsBehavior); Assert.AreEqual(rollInterval, rollingFile.RollInterval); Assert.AreEqual(RollAfterSize, rollingFile.RollSizeKB); Assert.AreEqual(TimeStampPattern, rollingFile.TimeStampPattern); Assert.AreEqual(NumberFiles, rollingFile.MaxArchivedFiles); Assert.AreEqual(FilePath, rollingFile.FileName); Assert.AreEqual(Footer, rollingFile.Footer); Assert.AreEqual(Header, rollingFile.Header); Assert.AreEqual(TraceOptions.None, rollingFile.TraceOutputOptions); Assert.AreEqual(FormatterName, rollingFile.Formatter); Assert.AreEqual(1, settings.Formatters.Count); var formatter = settings.Formatters.Get(FormatterName) as TextFormatterData; Assert.IsNotNull(formatter); Assert.AreEqual(Template, formatter.Template); }
/// <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); }
public ILoggingConfigurationSendToRollingFileTraceListener WhenRollFileExists(RollFileExistsBehavior behavior) { rollingTraceListenerData.RollFileExistsBehavior = behavior; return(this); }
/// <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)); }
public OperationTraceListener(string fileName, string header, string footer, ILogFormatter formatter, int rollSizeKB, string timeStampPattern, RollFileExistsBehavior rollFileExistsBehavior, RollInterval rollInterval) : base(fileName, header, footer, formatter, rollSizeKB, timeStampPattern, rollFileExistsBehavior, rollInterval) { }
public ILoggingConfigurationSendToRollingFileTraceListener WhenRollFileExists(RollFileExistsBehavior behavior) { rollingTraceListenerData.RollFileExistsBehavior = behavior; return this; }
/// <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; }