Esempio n. 1
0
        public static ILoggingBuilder AddRemoteHubReporter(this ILoggingBuilder logging, IConfiguration configuration)
        {
            if (_addRemoteHubReporterInvoked)
            {
                return(logging);
            }

            var remoteSection  = configuration.GetSection("RemoteHubReporter");
            var reporterConfig = new LogReporterConfig();

            remoteSection.Bind(reporterConfig);
            if (reporterConfig.IgnoreCategories != null)
            {
                RemoteIgnoreLoggers.Instance.AddIgnores(reporterConfig.IgnoreCategories.ToArray());
            }

            logging.Services.Configure <LogReporterConfig>(remoteSection);
            logging.Services.AddScoped(sp => sp.GetService <IOptionsSnapshot <LogReporterConfig> >().Value);
            //ok => use "IOptionsSnapshot<>" instead of "IOptions<>" will auto load after changed

            var remoteHubReporter = LogReporter.Instance;

            remoteHubReporter.Config = reporterConfig;

            logging.Services.AddSingleton(remoteHubReporter);
            logging.AddProvider(new RemoteLoggerProvider(reporterConfig.ClientId));

            //remoteHubReporter.TryStart(reporterConfig).Wait();
#pragma warning disable 4014
            remoteHubReporter.TryStart(reporterConfig);
#pragma warning restore 4014
            _addRemoteHubReporterInvoked = true;
            return(logging);
        }
Esempio n. 2
0
        public async Task <LogReporterStatus> TryStart(LogReporterConfig config)
        {
            await Init(config);

            var status = await GetStatus();

            return(status);
        }
Esempio n. 3
0
        public async Task Init(LogReporterConfig config)
        {
            Config = config ?? throw new ArgumentNullException(nameof(config));

            _closedAutoStart = false;
            if (Connection != null && Connection.State != HubConnectionState.Disconnected)
            {
                await Connection.StopAsync();
            }

            Connection = await TryInitHubConnection();

            _closedAutoStart = true;
            _initInvoked     = true;
        }