Пример #1
0
        public JobHostLifetime(IOptions <JobHostLifetimeOptions> options, IHostingEnvironment environment, IApplicationLifetime applicationLifetime, ILogger <JobHostLifetime> logger)
        {
            _options     = options?.Value ?? throw new ArgumentNullException(nameof(options));
            _environment = environment ?? throw new ArgumentNullException(nameof(environment));
            _lifetime    = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime));
            _logger      = logger ?? NullLogger <JobHostLifetime> .Instance;
            if (logger != NullLogger <JobHostLifetime> .Instance)
            {
                _useConsoleOutput = false;
            }

            _lifetime.ApplicationStarted.Register(() => {
                _timer = new Timer(e => CheckForShutdown(), null, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(2));

                if (_useConsoleOutput)
                {
                    Console.WriteLine("Application started. Press Ctrl+C to shut down.");
                    Console.WriteLine($"Hosting environment: {_environment.EnvironmentName}");
                    Console.WriteLine($"Content root path: {_environment.ContentRootPath}");
                }
                else
                {
                    _logger.LogInformation("Application started. Press Ctrl+C to shut down.");
                    _logger.LogInformation($"Hosting environment: {_environment.EnvironmentName}");
                    _logger.LogInformation($"Content root path: {_environment.ContentRootPath}");
                }
            });
        }
Пример #2
0
 public JobHostLifetime(IOptions <JobHostLifetimeOptions> options, IHostingEnvironment environment, IApplicationLifetime applicationLifetime, ILogger <JobHostLifetime> logger)
 {
     _options     = options?.Value ?? throw new ArgumentNullException(nameof(options));
     _environment = environment ?? throw new ArgumentNullException(nameof(environment));
     _lifetime    = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime));
     _logger      = logger ?? NullLogger <JobHostLifetime> .Instance;
     if (logger != NullLogger <JobHostLifetime> .Instance)
     {
         _useConsoleOutput = false;
     }
 }