Esempio n. 1
0
        /// <summary>
        /// Write log events to a sub-logger, where further processing may occur. Events through
        /// the sub-logger will be constrained by filters and enriched by enrichers that are
        /// active in the parent. A sub-logger cannot be used to log at a more verbose level, but
        /// a less verbose level is possible.
        /// </summary>
        /// <param name="configureLogger">An action that configures the sub-logger.</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 Logger(
            Action <LoggerConfiguration> configureLogger,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null)
        {
            if (configureLogger == null)
            {
                throw new ArgumentNullException(nameof(configureLogger));
            }
            var lc = new LoggerConfiguration();

            _applyInheritedConfiguration(lc);
            configureLogger(lc);

            var subLogger = lc.CreateLogger();

            if (subLogger.HasOverrideMap)
            {
                SelfLog.WriteLine("Minimum level overrides are not supported on sub-loggers " +
                                  "and may be removed completely in a future version.");
            }

            var secondarySink = new SecondaryLoggerSink(subLogger, attemptDispose: true);

            return(Sink(secondarySink, restrictedToMinimumLevel, levelSwitch));
        }
Esempio n. 2
0
        /// <summary>
        /// Write log events to a sub-logger, where further processing may occur. Events through
        /// the sub-logger will be constrained by filters and enriched by enrichers that are
        /// active in the parent. A sub-logger cannot be used to log at a more verbose level, but
        /// a less verbose level is possible.
        /// </summary>
        /// <param name="logger">The sub-logger. This will <em>not</em> be shut down automatically when the
        /// parent logger is disposed.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        public LoggerConfiguration Logger(
            ILogger logger,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (logger is Logger concreteLogger && concreteLogger.HasOverrideMap)
            {
                SelfLog.WriteLine("Minimum level overrides are not supported on sub-loggers " +
                                  "and may be removed completely in a future version.");
            }

            var secondarySink = new SecondaryLoggerSink(logger, attemptDispose: false);

            return(Sink(secondarySink, restrictedToMinimumLevel));
        }