public void AddRollingFileLogProviderMethod5SadPath()
        {
            ILoggerBuilder builder = null;

            Action act = () => builder.AddRollingFileLogProvider();

            act.Should().ThrowExactly <ArgumentNullException>().WithMessage("*builder*");
        }
 /// <summary>
 /// Adds a <see cref="RollingFileLogProvider"/>, formatted with a <see cref="ILogFormatter"/> of
 /// type <typeparamref name="TLogFormatter"/>, to the logger.
 /// </summary>
 /// <typeparam name="TLogFormatter">
 /// The type of <see cref="ILogFormatter"/> that the log provider uses for formatting logs.
 /// </typeparam>
 /// <param name="builder">The <see cref="ILoggerBuilder"/>.</param>
 /// <param name="file">The file to write to.</param>
 /// <param name="level">The logging level of the log provider.</param>
 /// <param name="timeout">The timeout of the log provider.</param>
 /// <param name="maxFileSizeKilobytes">
 /// The maximum file size, in bytes, of the file. If the file size is greater than this value,
 /// it is archived.
 /// </param>
 /// <param name="maxArchiveCount">
 /// The maximum number of archive files that will be kept. If the number of archive files is
 /// greater than this value, then they are deleted, oldest first.
 /// </param>
 /// <param name="rolloverPeriod">
 /// The rollover period, indicating if/how the file should archived on a periodic basis.
 /// </param>
 /// <param name="logFormatterParameters">
 /// Constructor arguments for type <typeparamref name="TLogFormatter"/> that are not provided
 /// by the <see cref="IServiceProvider"/>.
 /// </param>
 /// <returns>The same <see cref="ILoggerBuilder"/>.</returns>
 public static ILoggerBuilder AddRollingFileLogProvider <TLogFormatter>(this ILoggerBuilder builder,
                                                                        string file                   = null,
                                                                        LogLevel?level                = null,
                                                                        TimeSpan?timeout              = null,
                                                                        int?maxFileSizeKilobytes      = null,
                                                                        int?maxArchiveCount           = null,
                                                                        RolloverPeriod?rolloverPeriod = null,
                                                                        params object[] logFormatterParameters)
     where TLogFormatter : ILogFormatter
 {
     return(builder.AddRollingFileLogProvider(serviceProvider =>
                                              ActivatorUtilities.CreateInstance <TLogFormatter>(serviceProvider, logFormatterParameters),
                                              file, level, timeout, maxFileSizeKilobytes, maxArchiveCount, rolloverPeriod));
 }
        /// <summary>
        /// Adds a <see cref="RollingFileLogProvider"/>, formatted with the specified <see cref="ILogFormatter"/>,
        /// to the logger.
        /// </summary>
        /// <param name="builder">The <see cref="ILoggerBuilder"/>.</param>
        /// <param name="formatter">
        /// The <see cref="ILogFormatter"/> that the log provider uses for formatting logs.
        /// </param>
        /// <param name="file">The file to write to.</param>
        /// <param name="level">The logging level of the log provider.</param>
        /// <param name="timeout">The timeout of the log provider.</param>
        /// <param name="maxFileSizeKilobytes">
        /// The maximum file size, in bytes, of the file. If the file size is greater than this value,
        /// it is archived.
        /// </param>
        /// <param name="maxArchiveCount">
        /// The maximum number of archive files that will be kept. If the number of archive files is
        /// greater than this value, then they are deleted, oldest first.
        /// </param>
        /// <param name="rolloverPeriod">
        /// The rollover period, indicating if/how the file should archived on a periodic basis.
        /// </param>
        /// <returns>The same <see cref="ILoggerBuilder"/>.</returns>
        public static ILoggerBuilder AddRollingFileLogProvider(this ILoggerBuilder builder,
                                                               ILogFormatter formatter,
                                                               string file                   = null,
                                                               LogLevel?level                = null,
                                                               TimeSpan?timeout              = null,
                                                               int?maxFileSizeKilobytes      = null,
                                                               int?maxArchiveCount           = null,
                                                               RolloverPeriod?rolloverPeriod = null)
        {
            if (formatter is null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }

            return(builder.AddRollingFileLogProvider(serviceProvider => formatter,
                                                     file, level, timeout, maxFileSizeKilobytes, maxArchiveCount, rolloverPeriod));
        }
        /// <summary>
        /// Adds a <see cref="RollingFileLogProvider"/>, formatted with the <see cref="ILogFormatter"/>
        /// returned by the formatter registration, to the logger.
        /// </summary>
        /// <param name="builder">The <see cref="ILoggerBuilder"/>.</param>
        /// <param name="formatterRegistration">
        /// The method used to create the <see cref="ILogFormatter"/> of the log provider.
        /// </param>
        /// <param name="file">The file to write to.</param>
        /// <param name="level">The logging level of the log provider.</param>
        /// <param name="timeout">The timeout of the log provider.</param>
        /// <param name="maxFileSizeKilobytes">
        /// The maximum file size, in bytes, of the file. If the file size is greater than this value,
        /// it is archived.
        /// </param>
        /// <param name="maxArchiveCount">
        /// The maximum number of archive files that will be kept. If the number of archive files is
        /// greater than this value, then they are deleted, oldest first.
        /// </param>
        /// <param name="rolloverPeriod">
        /// The rollover period, indicating if/how the file should archived on a periodic basis.
        /// </param>
        /// <returns>The same <see cref="ILoggerBuilder"/>.</returns>
        public static ILoggerBuilder AddRollingFileLogProvider(this ILoggerBuilder builder,
                                                               Func <IServiceProvider, ILogFormatter> formatterRegistration,
                                                               string file                   = null,
                                                               LogLevel?level                = null,
                                                               TimeSpan?timeout              = null,
                                                               int?maxFileSizeKilobytes      = null,
                                                               int?maxArchiveCount           = null,
                                                               RolloverPeriod?rolloverPeriod = null)
        {
            if (formatterRegistration is null)
            {
                throw new ArgumentNullException(nameof(formatterRegistration));
            }

            return(builder.AddRollingFileLogProvider(options =>
            {
                options.FormatterRegistration = formatterRegistration;
                if (file != null)
                {
                    options.File = file;
                }
                if (level != null)
                {
                    options.Level = level.Value;
                }
                if (timeout != null)
                {
                    options.Timeout = timeout;
                }
                if (maxFileSizeKilobytes != null)
                {
                    options.MaxFileSizeKilobytes = maxFileSizeKilobytes.Value;
                }
                if (maxArchiveCount != null)
                {
                    options.MaxArchiveCount = maxArchiveCount.Value;
                }
                if (rolloverPeriod != null)
                {
                    options.RolloverPeriod = rolloverPeriod.Value;
                }
            }));
        }