internal static KafkaFailoverSink Create(KafkaSink kafkaSink, ILogEventSink fallbackSink, BatchOptions batchOptions, TimeSpan fallback) => batchOptions.QueueLimit.HasValue ? new KafkaFailoverSink(kafkaSink, fallbackSink, batchOptions.BatchSizeLimit, batchOptions.Period, batchOptions.QueueLimit.Value, fallback) : new KafkaFailoverSink(kafkaSink, fallbackSink, batchOptions.BatchSizeLimit, batchOptions.Period, fallback);
/// <summary> /// Initializes a new instance of the <see cref="AmazonS3Sink" /> class. /// </summary> /// <param name="formatter">The formatter.</param> /// <param name="path">The path.</param> /// <param name="fileSizeLimitBytes">The file size limit bytes.</param> /// <param name="buffered">if set to <c>true</c> [buffered].</param> /// <param name="encoding">The encoding.</param> /// <param name="rollingInterval">The rolling interval.</param> /// <param name="retainedFileCountLimit">The retained file count limit.</param> /// <param name="hooks">The hooks.</param> /// <param name="bucketName">The Amazon S3 bucket name.</param> /// <param name="endpoint">The Amazon S3 endpoint.</param> /// <param name="awsAccessKeyId">The Amazon S3 access key id.</param> /// <param name="awsSecretAccessKey">The Amazon S3 secret access key.</param> /// <returns>A <see cref="LoggerConfiguration" /> to use with Serilog.</returns> /// <exception cref="ArgumentNullException"> /// addSink /// or /// formatter /// or /// path /// </exception> /// <exception cref="ArgumentException"> /// Negative value provided; file size limit must be non-negative. - fileSizeLimitBytes /// or /// At least one file must be retained. - retainedFileCountLimit /// or /// Buffered writes are not available when file sharing is enabled. - buffered /// or /// File lifecycle hooks are not currently supported for shared log files. - hooks /// </exception> public AmazonS3Sink( ITextFormatter formatter, string path, long?fileSizeLimitBytes, bool buffered, Encoding encoding, RollingInterval rollingInterval, int?retainedFileCountLimit, FileLifecycleHooks hooks, string bucketName, RegionEndpoint endpoint, string awsAccessKeyId, string awsSecretAccessKey) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (string.IsNullOrWhiteSpace(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } if (string.IsNullOrWhiteSpace(awsAccessKeyId)) { throw new ArgumentNullException(nameof(awsAccessKeyId)); } if (string.IsNullOrWhiteSpace(awsSecretAccessKey)) { throw new ArgumentNullException(nameof(awsSecretAccessKey)); } if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes < 0) { throw new ArgumentException("Negative value provided; file size limit must be non-negative."); } if (retainedFileCountLimit.HasValue && retainedFileCountLimit < 1) { throw new ArgumentException( "Zero or negative value provided; retained file count limit must be at least 1."); } this.sink = new RollingFileSink( path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, rollingInterval, true, hooks, bucketName, endpoint, awsAccessKeyId, awsSecretAccessKey); }
internal static KafkaFailoverSink Create(KafkaSink kafkaSink, ILogEventSink fallbackSink, BatchOptions batchOptions, IModeSwitcher modeSwitcher) => batchOptions.QueueLimit.HasValue ? new KafkaFailoverSink(kafkaSink, fallbackSink, batchOptions.BatchSizeLimit, batchOptions.Period, batchOptions.QueueLimit.Value, modeSwitcher) : new KafkaFailoverSink(kafkaSink, fallbackSink, batchOptions.BatchSizeLimit, batchOptions.Period, modeSwitcher);
public override void BattleEnd() { LogProvider.DetachSink(_battleLogger); ((Logger)_battleLogger).Dispose(); _battleLogger = null; base.BattleEnd(); }
public FileSizeRolledDurableHttpSink( string requestUri, string bufferBaseFileName, long?bufferFileSizeLimitBytes, bool bufferFileShared, int?retainedBufferFileCountLimit, long?logEventLimitBytes, int?logEventsInBatchLimit, long?batchSizeLimitBytes, TimeSpan period, ITextFormatter textFormatter, IBatchFormatter batchFormatter, IHttpClient httpClient) { shipper = new HttpLogShipper( httpClient, requestUri, new FileSizeRolledBufferFiles(new DirectoryService(), bufferBaseFileName), logEventLimitBytes, logEventsInBatchLimit, batchSizeLimitBytes, period, batchFormatter); sink = CreateFileSink( bufferBaseFileName, bufferFileSizeLimitBytes, bufferFileShared, retainedBufferFileCountLimit, textFormatter); }
/// <summary> /// Write log events to the specified <see cref="ILogEventSink"/>. /// </summary> /// <param name="logEventSink">The sink.</param> /// <param name="restrictedToMinimumLevel">The minimum level for /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> /// <param name="levelSwitch">A switch allowing the pass-through minimum level /// to be changed at runtime.</param> /// <returns>Configuration object allowing method chaining.</returns> public LoggerConfiguration Sink( ILogEventSink logEventSink, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, // ReSharper disable once MethodOverloadWithOptionalParameter LoggingLevelSwitch levelSwitch = null) { var sink = logEventSink; if (levelSwitch != null) { if (restrictedToMinimumLevel != LevelAlias.Minimum) { SelfLog.WriteLine("Sink {0} was configured with both a level switch and minimum level '{1}'; the minimum level will be ignored and the switch level used", sink, restrictedToMinimumLevel); } sink = new RestrictedSink(sink, levelSwitch); } else if (restrictedToMinimumLevel > LevelAlias.Minimum) { sink = new RestrictedSink(sink, new LoggingLevelSwitch(restrictedToMinimumLevel)); } _addSink(sink); return(_loggerConfiguration); }
/// <summary> /// Initializes a new instance of the <see cref="FileSizeRolledDurableHttpSink"/> class. /// </summary> public FileSizeRolledDurableHttpSink( string requestUri, string bufferBaseFileName, long?bufferFileSizeLimitBytes, int?retainedBufferFileCountLimit, int batchPostingLimit, TimeSpan period, ITextFormatter textFormatter, IBatchFormatter batchFormatter, IHttpClient client) { if (bufferFileSizeLimitBytes.HasValue && bufferFileSizeLimitBytes < 0) { throw new ArgumentOutOfRangeException(nameof(bufferFileSizeLimitBytes), "Negative value provided; file size limit must be non-negative."); } shipper = new HttpLogShipper( client, requestUri, new FileSizeRolledBufferFiles(new DirectoryService(), bufferBaseFileName), batchPostingLimit, period, batchFormatter); sink = new LoggerConfiguration() .WriteTo.File( textFormatter, $"{bufferBaseFileName}-.json", fileSizeLimitBytes: bufferFileSizeLimitBytes, rollOnFileSizeLimit: true, retainedFileCountLimit: retainedBufferFileCountLimit, rollingInterval: RollingInterval.Day, encoding: Encoding.UTF8) .CreateLogger(); }
private KafkaFailoverSink(KafkaSink kafkaSink, ILogEventSink fallbackSink, int batchSizeLimit, TimeSpan period, int queueLimit, IModeSwitcher modeSwitcher) : base(batchSizeLimit, period, queueLimit) { _kafkaSink = kafkaSink; _fallbackSink = fallbackSink; _switcher = modeSwitcher; }
public static Logger CreateLogger(LoggerConfiguration seriConfig, ILogEventSink sink) { return(seriConfig .WriteTo .Sink(sink) .CreateLogger()); }
public FilteringSink(ILogEventSink sink, IEnumerable<ILogEventFilter> filters) { if (sink == null) throw new ArgumentNullException("sink"); if (filters == null) throw new ArgumentNullException("filters"); _sink = sink; _filters = filters.ToArray(); }
public ConcreteSinkWrapper(LogEventLevel logEventLevel, ILogEventSink sink) : base(logEventLevel) { Contract.Requires(sink != null); _sink = sink; }
/// <summary> /// Initializes a new instance of the <see cref="TimeRolledDurableHttpSink"/> class. /// </summary> public TimeRolledDurableHttpSink( string requestUri, string bufferPathFormat, long?bufferFileSizeLimitBytes, bool bufferFileShared, int?retainedBufferFileCountLimit, int batchPostingLimit, TimeSpan period, ITextFormatter textFormatter, IBatchFormatter batchFormatter, IHttpClient httpClient) { if (bufferFileSizeLimitBytes.HasValue && bufferFileSizeLimitBytes < 0) { throw new ArgumentOutOfRangeException(nameof(bufferFileSizeLimitBytes), "Negative value provided; file size limit must be non-negative."); } shipper = new HttpLogShipper( httpClient, requestUri, new TimeRolledBufferFiles(new DirectoryService(), bufferPathFormat), batchPostingLimit, period, batchFormatter); sink = new RollingFileSink( bufferPathFormat, textFormatter, bufferFileSizeLimitBytes, retainedBufferFileCountLimit, Encoding.UTF8, shared: bufferFileShared); }
public RestrictedSink(ILogEventSink sink, LoggingLevelSwitch levelSwitch) { if (sink == null) throw new ArgumentNullException(nameof(sink)); if (levelSwitch == null) throw new ArgumentNullException(nameof(levelSwitch)); _sink = sink; _levelSwitch = levelSwitch; }
void OpenFile(DateTime now) { var date = now.Date; // We only take one attempt at it because repeated failures // to open log files REALLY slow an app down. _nextCheckpoint = date.AddDays(1); var existingFiles = Enumerable.Empty <string>(); try { existingFiles = Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern) .Select(Path.GetFileName); } catch (DirectoryNotFoundException) { } var latestForThisDate = _roller .SelectMatches(existingFiles) .Where(m => m.Date == date) .OrderByDescending(m => m.SequenceNumber) .FirstOrDefault(); var sequence = latestForThisDate != null ? latestForThisDate.SequenceNumber : 0; const int maxAttempts = 3; for (var attempt = 0; attempt < maxAttempts; attempt++) { string path; _roller.GetLogFilePath(now, sequence, out path); try { #if SHARING _currentFile = _shared ? (ILogEventSink) new SharedFileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding) : new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered); #else _currentFile = new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered); #endif } catch (IOException ex) { var errorCode = Marshal.GetHRForException(ex) & ((1 << 16) - 1); if (errorCode == 32 || errorCode == 33) { SelfLog.WriteLine("Rolling file target {0} was locked, attempting to open next in sequence (attempt {1})", path, attempt + 1); sequence++; continue; } throw; } ApplyRetentionPolicy(path); return; } }
/// <summary> /// Audit log events to the specified <see cref="ILogEventSink"/>. /// </summary> /// <param name="logEventSink">The sink.</param> /// <param name="restrictedToMinimumLevel">The minimum level for /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param> /// <param name="levelSwitch">A switch allowing the pass-through minimum level /// to be changed at runtime.</param> /// <returns>Configuration object allowing method chaining.</returns> public LoggerConfiguration Sink( ILogEventSink logEventSink, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, // ReSharper disable once MethodOverloadWithOptionalParameter LoggingLevelSwitch levelSwitch = null) { return(_sinkConfiguration.Sink(logEventSink, restrictedToMinimumLevel, levelSwitch)); }
public static Logger GetLogger(ILogEventSink outputSink, params ILogEventEnricher[] enrichers) { return(new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.With(enrichers) .WriteTo.Sink(outputSink) .CreateLogger()); }
public PerRequestLogBuffer(int initialCapacity, LoggingLevelSpecification eventLevel, LoggingLevelSpecification allEventLevel, ILogEventSink sink) { _eventLevel = eventLevel; _allEventLevel = allEventLevel; _sink = sink; _eventEntries = new List <LogEventEntry>(initialCapacity); }
public static ILogger BuildSerilog(ILogEventSink sink) { return(new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Sink(sink) .CreateLogger() .ForContext <LoggerBenchmark>()); }
internal Logger( LoggingLevelSwitch levelSwitch, ILogEventSink sink, Action dispose = null, LevelOverrideMap overrideMap = null) : this(sink, new ExceptionDataEnricher(), dispose, levelSwitch, overrideMap) { }
public FilteringSink(ILogEventSink sink, IEnumerable<ILogEventFilter> filters, bool propagateExceptions) { if (sink == null) throw new ArgumentNullException(nameof(sink)); if (filters == null) throw new ArgumentNullException(nameof(filters)); _sink = sink; _propagateExceptions = propagateExceptions; _filters = filters.ToArray(); }
public CopyingSink(ILogEventSink copyToSink) { if (copyToSink == null) { throw new ArgumentNullException("copyToSink"); } _copyToSink = copyToSink; }
internal static LoggerConfiguration Sink( LoggerAuditSinkConfiguration auditSinkConfiguration, ILogEventSink sink, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum, LoggingLevelSwitch levelSwitch = null) { return(auditSinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch)); }
public void AddSink(ILogEventSink sink) { foreach (LogEvent previousEvent in _events) { sink.Emit(previousEvent); } _sinks.Enqueue(sink); }
/// <summary> /// Constructor /// </summary> /// <param name="wrappedSink"></param> /// <param name="minimumLevel"></param> /// <param name="fullDumpLevel"></param> /// <param name="controlLevelSwitch"></param> public BufferedSink(ILogEventSink wrappedSink, LogEventLevel minimumLevel, LogEventLevel fullDumpLevel, LoggingLevelSwitch controlLevelSwitch) { this.wrappedSink = wrappedSink; this.minimumLevel = minimumLevel; this.fullDumpLevel = fullDumpLevel; this.controlLevelSwitch = controlLevelSwitch; this.buffers = new ConcurrentDictionary <string, BlockingCollection <LogEvent> >(20, 50); }
public BufferedSink(LogEventLevel eventLevel, LogEventLevel allEventLevel, string requestIdProperty, int maxRequestAgeInSeconds, ILogEventSink innerSink) { _eventLevel = new LoggingLevelSpecification(eventLevel); _allEventLevel = new LoggingLevelSpecification(allEventLevel); _sink = innerSink; _requestIdProperty = requestIdProperty; _maxRequestAgeInSeconds = maxRequestAgeInSeconds; _buffers = new Dictionary <string, PerRequestLogBuffer>(); }
public RestrictedSink(ILogEventSink sink, LogEventLevel restrictedMinimumLevel) { if (sink == null) { throw new ArgumentNullException("sink"); } _sink = sink; _restrictedMinimumLevel = restrictedMinimumLevel; }
internal Logger( LoggingLevelSwitch levelSwitch, ILogEventSink sink, ILogEventEnricher enricher, Action dispose = null, LevelOverrideMap overrideMap = null) : this(sink, enricher, dispose, levelSwitch, overrideMap) { }
public Emitter(ILogEventSink sink, ILogEventMapper mapper = null) { if (sink == null) { throw new ArgumentNullException(); } _sink = sink; _mapper = mapper ?? new DefaultLogEventMapper(); }
public Logger( MessageTemplateProcessor messageTemplateProcessor, LoggingLevelSwitch levelSwitch, ILogEventSink sink, IEnumerable <ILogEventEnricher> enrichers, Action dispose = null) : this(messageTemplateProcessor, LevelAlias.Minimum, sink, enrichers, dispose, levelSwitch) { }
public Logger( MessageTemplateProcessor messageTemplateProcessor, LogEventLevel minimumLevel, ILogEventSink sink, IEnumerable <ILogEventEnricher> enrichers, Action dispose = null) : this(messageTemplateProcessor, minimumLevel, sink, enrichers, dispose, null) { }
void CloseFile() { if (_currentFile != null) { (_currentFile as IDisposable)?.Dispose(); _currentFile = null; } _nextCheckpoint = null; }
public FilteringSink(ILogEventSink sink, IEnumerable <ILogEventFilter> filters, bool propagateExceptions) { if (filters == null) { throw new ArgumentNullException(nameof(filters)); } _sink = sink ?? throw new ArgumentNullException(nameof(sink)); _propagateExceptions = propagateExceptions; _filters = filters.ToArray(); }
private static ILogEventSink ApplyBlockDuplicatedLogDecorator(ILogEventSink logEventSink, int minutesForBlockDuplicatedLog, MemoryCache memoryCache = null) { if (memoryCache is null) { memoryCache = new MemoryCache(new MemoryCacheOptions()); } var timespan = TimeSpan.FromMinutes(minutesForBlockDuplicatedLog); var decorator = new BlockDuplicatedLogSinkDecorator(logEventSink, memoryCache, timespan); return(decorator); }
/// <summary> /// Write log events to the specified <see cref="ILogEventSink"/>. /// </summary> /// <param name="logEventSink">The sink.</param> /// <param name="restrictedToMinimumLevel">The minimum level for /// events passed through the sink.</param> /// <returns>Configuration object allowing method chaining.</returns> public LoggerConfiguration Sink( ILogEventSink logEventSink, LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum) { var sink = logEventSink; if (restrictedToMinimumLevel > LevelAlias.Minimum) sink = new RestrictedSink(sink, restrictedToMinimumLevel); _addSink(sink); return _loggerConfiguration; }
public CopyingSink(ILogEventSink copyToSink) { if (copyToSink == null) throw new ArgumentNullException("copyToSink"); _copyToSink = copyToSink; }
/// <summary> /// Write log events to the specified <see cref="ILogEventSink"/>. /// </summary> /// <param name="logEventSink">The sink.</param> /// <param name="restrictedToMinimumLevel">The minimum level for /// events passed through the sink.</param> /// <returns>Configuration object allowing method chaining.</returns> public LoggerConfiguration WithSink(ILogEventSink logEventSink, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Minimum) { var sink = logEventSink; if (restrictedToMinimumLevel > LogEventLevel.Minimum) sink = new RestrictedSink(sink, restrictedToMinimumLevel); _logEventSinks.Add(sink); return this; }
public RestrictedSink(ILogEventSink sink, LogEventLevel restrictedMinimumLevel) { if (sink == null) throw new ArgumentNullException("sink"); _sink = sink; _restrictedMinimumLevel = restrictedMinimumLevel; }