/// <summary> /// Emits a log event to this sink /// </summary> /// <param name="logEvent">The <see cref="LogEvent"/> to emit</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ObjectDisposedException"></exception> public void Emit(LogEvent logEvent) { if (logEvent == null) { throw new ArgumentNullException("logEvent"); } lock (this.syncRoot) { if (this.disposed) { throw new ObjectDisposedException(ThisObjectName, "The rolling file sink has been disposed"); } if (!this.currentSink.LogFileDescription.SameHour(logEvent.Timestamp.UtcDateTime)) { this.currentSink = this.NextFileSink(logEvent.Timestamp.UtcDateTime); } if (this.currentSink != null) { this.currentSink.Emit(logEvent); } } }
/// <summary> /// Construct a <see cref="HourlyRollingFileSink"/> /// </summary> /// <param name="logDirectory"></param> /// <param name="formatter">The size in bytes at which a new file should be created</param> /// <param name="encoding"></param> public HourlyRollingFileSink( string logDirectory, ITextFormatter formatter, Encoding encoding = null) { this.formatter = formatter; this.encoding = encoding; this.logDirectory = logDirectory; this.currentSink = this.GetLatestSink(); }
/// <summary> /// Construct a <see cref="HourlyRollingFileSink"/> /// </summary> /// <param name="logDirectory"></param> /// <param name="formatter">The size in bytes at which a new file should be created</param> /// <param name="retainedFileCountLimit">The maximum number of log files that will be retained, /// including the current log file. The default is null which is unlimited.</param> /// <param name="encoding"></param> public HourlyRollingFileSink( string logDirectory, ITextFormatter formatter, int?retainedFileCountLimit = null, Encoding encoding = null) { this.formatter = formatter; this.retainedFileCountLimit = retainedFileCountLimit; this.encoding = encoding; this.logDirectory = logDirectory; this.currentSink = this.GetLatestSink(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> public void Dispose() { lock (this.syncRoot) { if (!this.disposed && this.currentSink != null) { this.currentSink.Dispose(); this.currentSink = null; this.disposed = true; } } }