修改dns服务启动时逻辑顺序

This commit is contained in:
xljiulang 2021-07-20 20:31:42 +08:00
parent 4ae101a76f
commit 7bb7da063c
2 changed files with 9 additions and 7 deletions

View File

@ -70,6 +70,7 @@ namespace FastGithub.Dns.DnscryptProxy
if (this.dnscryptProcess != null) if (this.dnscryptProcess != null)
{ {
this.dnscryptProcess.Kill(); this.dnscryptProcess.Kill();
this.logger.LogInformation($"{dnscryptFile}已停止");
} }
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -56,9 +56,10 @@ namespace FastGithub.Dns
public override async Task StartAsync(CancellationToken cancellationToken) public override async Task StartAsync(CancellationToken cancellationToken)
{ {
await this.BindAsync(cancellationToken); await this.BindAsync(cancellationToken);
await this.hostsValidator.ValidateAsync(); this.logger.LogInformation("DNS服务启动成功");
this.SetAsPrimitiveNameServer(); this.SetAsPrimitiveNameServer();
this.logger.LogInformation("dns服务启动成功"); await this.hostsValidator.ValidateAsync();
await base.StartAsync(cancellationToken); await base.StartAsync(cancellationToken);
} }
@ -113,16 +114,16 @@ namespace FastGithub.Dns
{ {
SystemDnsUtil.DnsSetPrimitive(IPAddress.Loopback); SystemDnsUtil.DnsSetPrimitive(IPAddress.Loopback);
SystemDnsUtil.DnsFlushResolverCache(); SystemDnsUtil.DnsFlushResolverCache();
this.logger.LogInformation($"设置为本机dns成功"); this.logger.LogInformation($"设置为本机主DNS成功");
} }
catch (Exception ex) catch (Exception ex)
{ {
this.logger.LogWarning($"设置为本机dns失败:{ex.Message}"); this.logger.LogWarning($"设置为本机主DNS失败:{ex.Message}");
} }
} }
else else
{ {
this.logger.LogWarning("平台不支持自动设置dns请手动设置网卡的主dns为127.0.0.1"); this.logger.LogWarning("平台不支持自动设置DNS请手动设置网卡的主DNS为127.0.0.1");
} }
} }
@ -167,7 +168,7 @@ namespace FastGithub.Dns
} }
catch (Exception ex) catch (Exception ex)
{ {
this.logger.LogTrace($"处理dns异常:{ex.Message}"); this.logger.LogTrace($"处理DNS异常:{ex.Message}");
} }
} }
@ -179,7 +180,7 @@ namespace FastGithub.Dns
public override Task StopAsync(CancellationToken cancellationToken) public override Task StopAsync(CancellationToken cancellationToken)
{ {
this.socket.Dispose(); this.socket.Dispose();
this.logger.LogInformation("dns服务已终止"); this.logger.LogInformation("DNS服务已停止");
if (OperatingSystem.IsWindows()) if (OperatingSystem.IsWindows())
{ {