dns日志

This commit is contained in:
陈国伟 2021-11-17 09:37:30 +08:00
parent 5f2a1f4804
commit 7d7b67948b
4 changed files with 19 additions and 13 deletions

View File

@ -117,20 +117,16 @@ namespace FastGithub.DomainResolve
var result = await this.LookupCoreAsync(dns, endPoint, cancellationToken);
this.dnsCache.Set(key, result.Addresses, result.TimeToLive);
var items = string.Join(", ", result.Addresses.Select(item => item.ToString()));
this.logger.LogInformation($"dns://{dns}{endPoint.Host}->[{items}]");
return result.Addresses;
}
catch (OperationCanceledException)
{
this.logger.LogInformation($"dns://{dns}无法解析{endPoint.Host}:请求超时");
this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}:请求超时");
return Array.Empty<IPAddress>();
}
catch (Exception ex)
{
this.logger.LogInformation($"dns://{dns}无法解析{endPoint.Host}{ex.Message}");
this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}{ex.Message}");
return Array.Empty<IPAddress>();
}
finally

View File

@ -1,4 +1,5 @@
using FastGithub.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -16,15 +17,18 @@ namespace FastGithub.DomainResolve
sealed class DomainResolver : IDomainResolver
{
private readonly DnsClient dnsClient;
private readonly ILogger<DomainResolver> logger;
private readonly ConcurrentDictionary<DnsEndPoint, IPAddressElapsedCollection> dnsEndPointAddressElapseds = new();
/// <summary>
/// 域名解析器
/// </summary>
/// <param name="dnsClient"></param>
public DomainResolver(DnsClient dnsClient)
/// <param name="logger"></param>
public DomainResolver(DnsClient dnsClient, ILogger<DomainResolver> logger)
{
this.dnsClient = dnsClient;
this.logger = logger;
}
/// <summary>
@ -52,6 +56,7 @@ namespace FastGithub.DomainResolve
{
if (this.dnsEndPointAddressElapseds.TryGetValue(endPoint, out var addressElapseds) && addressElapseds.IsEmpty == false)
{
this.logger.LogInformation($"{endPoint.Host}: {addressElapseds}");
foreach (var addressElapsed in addressElapseds)
{
yield return addressElapsed.Adddress;

View File

@ -76,5 +76,10 @@ namespace FastGithub.DomainResolve
{
return this.addressElapseds.GetEnumerator();
}
public override string ToString()
{
return $"[{string.Join(',', this.addressElapseds.Select(item => item.Adddress))}]";
}
}
}

View File

@ -2,9 +2,10 @@
// appsettings.*.json
"FastGithub": {
"HttpProxyPort": 38457, // httplinux/osx使
"FallbackDns": [ // dnscrypt-proxy使
"FallbackDns": [ // dnstcp
"114.114.114.114:53",
"119.29.29.29:53"
"119.29.29.29:53",
"208.67.222.222:53"
],
"DomainConfigs": {
"*.fastgithub.com": { // *.0
@ -29,7 +30,6 @@
"Yarp": "Warning",
"System": "Warning",
"Microsoft": "Warning",
"FastGithub.DomainResolve": "Warning",
"Microsoft.AspNetCore.Server.Kestrel": "Error"
}
}