public static LoggerConfiguration Async(
     this LoggerSinkConfiguration loggerSinkConfiguration,
     Action <LoggerSinkConfiguration> configure,
     int bufferSize)
 {
     return(loggerSinkConfiguration.Async(configure, bufferSize, false));
 }
Ejemplo n.º 2
0
 /// <remarks>
 ///    Used in config - If renamed or moved to other assembly the config file also has be updated.
 /// </remarks>
 public static LoggerConfiguration File(this LoggerSinkConfiguration configuration, ITextFormatter formatter,
                                        string path,
                                        LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
                                        LoggingLevelSwitch levelSwitch         = null,
                                        long?fileSizeLimitBytes         = 1073741824,
                                        TimeSpan?flushToDiskInterval    = null,
                                        RollingInterval rollingInterval = RollingInterval.Infinite,
                                        bool rollOnFileSizeLimit        = false,
                                        int?retainedFileCountLimit      = 31,
                                        Encoding encoding = null
                                        )
 {
     return(configuration.Async(
                asyncConfiguration => asyncConfiguration.Map(AppDomainId, (_, mapConfiguration) =>
                                                             mapConfiguration.File(
                                                                 formatter,
                                                                 path,
                                                                 restrictedToMinimumLevel,
                                                                 fileSizeLimitBytes,
                                                                 levelSwitch,
                                                                 buffered: true,
                                                                 shared: false,
                                                                 flushToDiskInterval,
                                                                 rollingInterval,
                                                                 rollOnFileSizeLimit,
                                                                 retainedFileCountLimit,
                                                                 encoding),
                                                             sinkMapCountLimit: 0)
                ));
 }
 public static LoggerConfiguration Buffer(this LoggerSinkConfiguration loggerSinkConfiguration,
                                          Action <LoggerSinkConfiguration> configure, LogEventLevel minimumLevel = LogEventLevel.Information,
                                          LogEventLevel fullDumpLevel = LogEventLevel.Error, LoggingLevelSwitch controlLevelSwitch = null)
 {
     return(loggerSinkConfiguration.Async(builder => LoggerSinkConfiguration.Wrap(
                                              builder, wrappedSink => new BufferedSink(wrappedSink, minimumLevel, fullDumpLevel, controlLevelSwitch),
                                              configure, LevelAlias.Minimum, null)));
 }
 /// <summary>
 /// Configure a sink to be invoked asynchronously, on a background worker thread.
 /// </summary>
 /// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param>
 /// <param name="configure">An action that configures the wrapped sink.</param>
 /// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If
 /// the thread is unable to process events quickly enough and the queue is filled, depending on
 /// <paramref name="blockWhenFull"/> the queue will block or subsequent events will be dropped until
 /// room is made in the queue.</param>
 /// <param name="blockWhenFull">Block when the queue is full, instead of dropping events.</param>
 /// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns>
 public static LoggerConfiguration Async(
     this LoggerSinkConfiguration loggerSinkConfiguration,
     Action <LoggerSinkConfiguration> configure,
     int bufferSize     = 10000,
     bool blockWhenFull = false)
 {
     return(loggerSinkConfiguration.Async(configure, null, bufferSize, blockWhenFull));
 }
Ejemplo n.º 5
0
        public static LoggerConfiguration SuperRollingFileAlternate(
            this LoggerSinkConfiguration configuration,
            string logDirectory,
            string logFilePrefix = "",
            SuperRollingFileAlternateFormats format = SuperRollingFileAlternateFormats.Text,
            ITextFormatter formatter   = null,
            LogEventLevel minimumLevel = LevelAlias.Minimum,
            long fileSizeLimitBytes    = DefaultFileSizeLimitBytes,
            int?retainedFileCountLimit = DefaultRetainedFileCountLimit,
            Encoding encoding          = null,
            bool renderMessage         = false,
            bool async                     = false,
            string outputTemplate          = DefaultOutputTemplate,
            IFormatProvider formatProvider = null)
        {
            if (formatter == null)
            {
                switch (format)
                {
                case SuperRollingFileAlternateFormats.Json:
                    formatter = new JsonFormatter(renderMessage: renderMessage);
                    break;

                case SuperRollingFileAlternateFormats.CompactJson:
                    formatter = new CompactJsonFormatter();
                    break;

                case SuperRollingFileAlternateFormats.Text:
                default:
                    formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
                    break;
                }
            }
            var sink = new AlternateRollingFileSink(logDirectory, formatter, fileSizeLimitBytes,
                                                    retainedFileCountLimit, encoding, logFilePrefix);

            if (async)
            {
                return(configuration.Async(c => c.Sink(sink, minimumLevel)));
            }
            else
            {
                return(configuration.Sink(sink, minimumLevel));
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Write log events to a series of files. Each file will be named according to
 /// the date of the first log entry written to it. Only simple date-based rolling is
 /// currently supported.
 /// </summary>
 /// <param name="loggerSinkConfiguration">Logger sink configuration.</param>
 /// <param name="formatter">Formatter to control how events are rendered into the file. To control
 /// plain text formatting, use the overload that accepts an output template instead.</param>
 /// <param name="pathFormat">String describing the location of the log files,
 /// with {Date} in the place of the file date. E.g. "Logs\myapp-{Date}.log" will result in log
 /// files such as "Logs\myapp-2013-10-20.log", "Logs\myapp-2013-10-21.log" and so on.</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>
 /// <param name="fileSizeLimitBytes">The maximum size, in bytes, to which any single log file will be allowed to grow.
 /// For unrestricted growth, pass null. The default is 1 GB.</param>
 /// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
 /// including the current log file. For unlimited retention, pass null. The default is 31.</param>
 /// <param name="buffered">Indicates if flushing to the output file can be buffered or not.
 /// The default is false.</param>
 /// <param name="shared">Allow the log files to be shared by multiple processes. The default is false.</param>
 /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
 /// <param name="asyncBufferSize">The size of the concurrent queue used to feed the background worker thread. If
 /// the thread is unable to process events quickly enough and the queue is filled, subsequent events will be
 /// dropped until room is made in the queue.</param>
 /// <returns>Configuration object allowing method chaining.</returns>
 /// <remarks>The file will be written using the UTF-8 encoding without a byte-order mark.</remarks>
 public static LoggerConfiguration RollingFileAsync(
     this LoggerSinkConfiguration loggerSinkConfiguration,
     ITextFormatter formatter,
     string pathFormat,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     long?fileSizeLimitBytes        = DefaultFileSizeLimitBytes,
     int?retainedFileCountLimit     = DefaultRetainedFileCountLimit,
     LoggingLevelSwitch levelSwitch = null,
     bool buffered = false,
     bool shared   = false,
     TimeSpan?flushToDiskInterval = null,
     int asyncBufferSize          = 10000)
 {
     return(loggerSinkConfiguration.Async(
                lsc => {
         lsc.RollingFile(
             formatter, pathFormat, restrictedToMinimumLevel, fileSizeLimitBytes,
             retainedFileCountLimit, levelSwitch, buffered, shared, flushToDiskInterval);
     },
                asyncBufferSize));
 }
Ejemplo n.º 7
0
        /// <remarks>
        ///    Used in config - If renamed or moved to other assembly the config file also has be updated.
        /// </remarks>
        public static LoggerConfiguration UmbracoFile(
            this LoggerSinkConfiguration configuration,
            string path,
            ITextFormatter?formatter = null,
            LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose,
            LoggingLevelSwitch?levelSwitch         = null,
            long?fileSizeLimitBytes         = 1073741824,
            TimeSpan?flushToDiskInterval    = null,
            RollingInterval rollingInterval = RollingInterval.Day,
            bool rollOnFileSizeLimit        = false,
            int?retainedFileCountLimit      = 31,
            Encoding?encoding = null
            )
        {
            formatter ??= new CompactJsonFormatter();

            /* Async sink has an event buffer of 10k events (by default) so we're not constantly thrashing the disk.
             * I noticed that with File buffered + large number of log entries (global minimum Debug)
             * an ungraceful shutdown would consistently result in output that just stops halfway through an entry.
             * with buffered false on the inner sink ungraceful shutdowns still don't seem to wreck the file.
             */
            return(configuration.Async(
                       cfg =>
                       cfg.File(
                           formatter,
                           path,
                           restrictedToMinimumLevel,
                           fileSizeLimitBytes,
                           levelSwitch,
                           buffered: false, // see notes above.
                           shared: false,
                           flushToDiskInterval,
                           rollingInterval,
                           rollOnFileSizeLimit,
                           retainedFileCountLimit,
                           encoding,
                           null)));
        }
        /// <summary>
        /// Write log events to a series of files asynchronously. Each file will be named according to
        /// the date of the first log entry written to it. Only simple date-based rolling is
        /// currently supported.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="formatter">Formatter to control how events are rendered into the file. To control
        /// plain text formatting, use the overload that accepts an output template instead.</param>
        /// <param name="pathFormat">String describing the location of the log files,
        /// with {Date} in the place of the file date. E.g. "Logs\myapp-{Date}.log" will result in log
        /// files such as "Logs\myapp-2013-10-20.log", "Logs\myapp-2013-10-21.log" and so on.</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>
        /// <param name="fileSizeLimitBytes">The maximum size, in bytes, to which any single log file will be allowed to grow.
        /// For unrestricted growth, pass null. The default is 1 GB.</param>
        /// <param name="retainedFileCountLimit">The maximum number of log files that will be retained,
        /// including the current log file. For unlimited retention, pass null. The default is 31.</param>
        /// <param name="buffered">Indicates if flushing to the output file can be buffered or not. The default
        /// is false.</param>
        /// <param name="shared">Allow the log files to be shared by multiple processes. The default is false.</param>
        /// <param name="flushToDiskInterval">If provided, a full disk flush will be performed periodically at the specified interval.</param>
        /// <param name="queueSize">The size of the concurrent queue used to feed the background worker thread. If
        /// the thread is unable to process events quickly enough and the queue is filled, subsequent events will be
        /// dropped until room is made in the queue.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        /// <remarks>The file will be written using the UTF-8 encoding without a byte-order mark.</remarks>
        public static LoggerConfiguration AsyncRollingFile(
            this LoggerSinkConfiguration sinkConfiguration,
            ITextFormatter formatter,
            string pathFormat,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            long?fileSizeLimitBytes        = DefaultFileSizeLimitBytes,
            int?retainedFileCountLimit     = DefaultRetainedFileCountLimit,
            LoggingLevelSwitch levelSwitch = null,
            bool buffered = false,
            bool shared   = false,
            TimeSpan?flushToDiskInterval = null,
            int queueSize = 65536)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            if (shared && buffered)
            {
                throw new ArgumentException("Buffered writes are not available when file sharing is enabled.", nameof(buffered));
            }

            ILogEventSink sink = new RollingFileSink(pathFormat, formatter, fileSizeLimitBytes, retainedFileCountLimit, buffered: buffered, shared: shared);

            if (flushToDiskInterval.HasValue)
            {
                sink = new PeriodicFlushToDiskSink(sink, flushToDiskInterval.Value);
            }

            return(sinkConfiguration.Async(c => c.Sink(sink, restrictedToMinimumLevel, levelSwitch), queueSize));
        }