Esempio n. 1
0
 /// <summary>
 /// Constructor.
 /// <para>The IOptionsMonitor provides the OnChange() method which is called when the user alters the settings of this provider in the appsettings.json file.</para>
 /// </summary>
 public WebLoggerProvider(IOptionsMonitor <WebLoggerOptions> settings, IWebLoggerDestination webLoggerDestination)
     : this(settings.CurrentValue, webLoggerDestination)
 {
     // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/change-tokens
     SettingsChangeToken = settings.OnChange(settings =>
     {
         _settings = settings;
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Adds the file logger provider, aliased as 'Web', in the available services as singleton and binds the file logger options class to the 'File' section of the appsettings.json file.
        /// </summary>
        public static ILoggingBuilder AddWebLogger(this ILoggingBuilder builder, IWebLoggerDestination webLoggerDestination, Action <WebLoggerOptions> configure)
        {
            if (configure is null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            builder.AddWebLogger(webLoggerDestination);
            builder.Services.Configure(configure);

            return(builder);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the file logger provider, aliased as 'Web', in the available services as singleton and binds the file logger options class to the 'Web' section of the appsettings.json file.
        /// </summary>
        public static ILoggingBuilder AddWebLogger(this ILoggingBuilder builder, IWebLoggerDestination webLoggerDestination)
        {
            builder.AddConfiguration();

            builder.Services.TryAddSingleton <ILoggerProvider>((serviceProvider) =>
            {
                IOptionsMonitor <WebLoggerOptions> options = serviceProvider.GetRequiredService <IOptionsMonitor <WebLoggerOptions> >();
                return(new WebLoggerProvider(options, webLoggerDestination));
            });
            builder.Services.TryAddSingleton <IConfigureOptions <WebLoggerOptions>, WebLoggerOptionsSetup>();
            builder.Services.TryAddSingleton <IOptionsChangeTokenSource <WebLoggerOptions>, LoggerProviderOptionsChangeTokenSource <WebLoggerOptions, WebLoggerProvider> >();

            return(builder);
        }
Esempio n. 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 public WebLoggerProvider(WebLoggerOptions settings, IWebLoggerDestination webLoggerDestination)
 {
     _webLoggerDestination = webLoggerDestination;
     _settings             = settings;
 }
Esempio n. 5
0
        public IWebLoggerDestination Add(string id, IWebLoggerDestination destination)
        {
            _destinations.TryAdd(id, destination);

            return(destination);
        }