mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-21 19:32:35 +10:00
Reorganise Infrastructure/Services into feature namespaces
- Move registration marker interfaces to Registration/Abstractions - Add feature folders with Abstractions subfolders: EffectiveConfig, Dnsmasq/Config, Dnsmasq/Hosts, Dnsmasq/Leases, Dnsmasq/Reload, Logs, Updates, UI/Settings, Common/Process - Place interfaces in each feature's Abstractions namespace; align implementation namespaces to folder paths - Update Program, extensions, controllers, hubs, helpers, components, and tests to use new namespaces - Remove old flat Services/Abstractions and root-level service files
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using DnsmasqWebUI.Infrastructure.Services.Registration.Abstractions;
|
||||
using DnsmasqWebUI.Models.Config;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DnsmasqWebUI.Infrastructure.Services.Logs;
|
||||
|
||||
/// <summary>Logs application start and stop with runtime and configuration context.</summary>
|
||||
public sealed class ApplicationLifecycleLoggingHostedService : IApplicationHostedService
|
||||
{
|
||||
private readonly ILogger<ApplicationLifecycleLoggingHostedService> _logger;
|
||||
private readonly IHostEnvironment _env;
|
||||
private readonly DnsmasqOptions _dnsmasq;
|
||||
private readonly DateTimeOffset _startedAt;
|
||||
|
||||
public ApplicationLifecycleLoggingHostedService(
|
||||
ILogger<ApplicationLifecycleLoggingHostedService> logger,
|
||||
IHostEnvironment env,
|
||||
IOptions<DnsmasqOptions> dnsmasq)
|
||||
{
|
||||
_logger = logger;
|
||||
_env = env;
|
||||
_dnsmasq = dnsmasq.Value;
|
||||
_startedAt = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var version = typeof(ApplicationLifecycleLoggingHostedService).Assembly
|
||||
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "?";
|
||||
var mainDir = Path.GetDirectoryName(Path.GetFullPath(_dnsmasq.MainConfigPath)) ?? "";
|
||||
var managedConfigPath = Path.Combine(mainDir, _dnsmasq.ManagedFileName);
|
||||
var managedHostsPath = Path.Combine(mainDir, _dnsmasq.ManagedHostsFileName);
|
||||
|
||||
_logger.LogInformation(
|
||||
"Application started: version={Version}, env={Environment}, os={OS}, arch={Arch}. " +
|
||||
"MainConfig={MainConfig}, managedConfig={ManagedConfig}, managedHosts={ManagedHosts}, systemHosts={SystemHosts}. " +
|
||||
"ReloadCommand={ReloadCmd}, StatusCommand={StatusCmd}",
|
||||
version,
|
||||
_env.EnvironmentName,
|
||||
RuntimeInformation.OSDescription.Trim(),
|
||||
RuntimeInformation.OSArchitecture,
|
||||
_dnsmasq.MainConfigPath,
|
||||
managedConfigPath,
|
||||
managedHostsPath,
|
||||
_dnsmasq.SystemHostsPath ?? "(not set)",
|
||||
string.IsNullOrWhiteSpace(_dnsmasq.ReloadCommand) ? "(not set)" : _dnsmasq.ReloadCommand,
|
||||
string.IsNullOrWhiteSpace(_dnsmasq.StatusCommand) ? "(not set)" : _dnsmasq.StatusCommand);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var uptime = DateTimeOffset.UtcNow - _startedAt;
|
||||
_logger.LogInformation("Application stopping: uptime={Uptime:F1}s", uptime.TotalSeconds);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user