コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerilogDynamicProvider"/> class.
        /// Any Serilog settings can be passed in the IConfiguration as needed.
        /// </summary>
        /// <param name="configuration">Serilog readable <see cref="IConfiguration"/></param>
        /// <param name="logger">Serilog logger<see cref="Serilog.Core.Logger"/></param>
        /// <param name="loggingLevelSwitch">Serilog global log level switch<see cref="LoggingLevelSwitch"/></param>
        /// <param name="options">Subset of Serilog options managed by wrapper<see cref="ISerilogOptions"/></param>
        public SerilogDynamicProvider(IConfiguration configuration, ISerilogOptions options = null, Logger logger = null, LoggingLevelSwitch loggingLevelSwitch = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _serilogOptions = options ?? new SerilogOptions(configuration);

            _subLoggerConfiguration = new ConfigurationBuilder()
                                      .AddInMemoryCollection(configuration.GetSection(_serilogOptions.ConfigPath)
                                                             .AsEnumerable().Where((kv) => !_serilogOptions.FullnameExclusions.Any(key => kv.Key.StartsWith(key))))
                                      .Build();

            SetFiltersFromOptions();

            // Add a level switch that controls the "Default" level at the root
            if (loggingLevelSwitch == null)
            {
                _defaultLevel      = _serilogOptions.MinimumLevel.Default;
                loggingLevelSwitch = new LoggingLevelSwitch(_defaultLevel.Value);
            }
            else
            {
                _defaultLevel = loggingLevelSwitch.MinimumLevel;
            }

            _loggerSwitches.GetOrAdd("Default", loggingLevelSwitch);

            // Add a global logger that will be the root of all other added loggers
            _globalLogger = logger ??
                            SerilogConfigurationExtensions.GetDefaultSerilogConfiguration(configuration)
                            .MinimumLevel.ControlledBy(loggingLevelSwitch)
                            .CreateLogger();
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerilogDynamicProvider"/> class.
        /// Any Serilog settings can be passed in the IConfiguration as needed.
        /// </summary>
        /// <param name="configuration">Serilog readable <see cref="IConfiguration"/></param>
        /// <param name="logger">Serilog logger<see cref="Serilog.Core.Logger"/></param>
        /// <param name="loggingLevelSwitch">Serilog global log level switch<see cref="Serilog.Core.LoggingLevelSwitch"/></param>
        /// <param name="options">Subset of Serilog options managed by wrapper<see cref="ISerilogOptions"/></param>
        public SerilogDynamicProvider(IConfiguration configuration, Logger logger, LoggingLevelSwitch loggingLevelSwitch, ISerilogOptions options = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _serilogOptions = options ?? new SerilogOptions(configuration);

            // Add a level switch that controls the "Default" level at the root
            _loggerSwitches.GetOrAdd("Default", loggingLevelSwitch);

            // Add a global logger that will be the root of all other added loggers
            _globalLogger = logger;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerilogDynamicProvider"/> class.
        /// Any Serilog settings can be passed in the IConfiguration as needed.
        /// </summary>
        /// <param name="configuration">Serilog readable <see cref="IConfiguration"/></param>
        /// <param name="options">Subset of Serilog options managed by wrapper<see cref="ISerilogOptions"/></param>
        public SerilogDynamicProvider(IConfiguration configuration, ISerilogOptions options = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _serilogOptions = options ?? new SerilogOptions(configuration);

            // Add a level switch that controls the "Default" level at the root
            var levelSwitch = new LoggingLevelSwitch(_serilogOptions.MinimumLevel.Default);

            _loggerSwitches.GetOrAdd("Default", levelSwitch);

            // Add a global logger that will be the root of all other added loggers
            _globalLogger = new Serilog.LoggerConfiguration()
                            .MinimumLevel.ControlledBy(levelSwitch)
                            .ReadFrom.Configuration(configuration)
                            .CreateLogger();
        }
コード例 #4
0
 public SerilogDynamicProvider(IConfiguration configuration, Logger logger, LoggingLevelSwitch loggingLevelSwitch, ISerilogOptions options = null)
     : this(configuration, options, logger, loggingLevelSwitch)
 {
 }
コード例 #5
0
 public LoggingInterceptionBehavior(ILogger logger, IStopWatch stopWatch, ISerilogOptions options)
 {
     _logger    = logger;
     _stopWatch = stopWatch;
     _options   = options;
 }