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); var result = await this.LookupCoreAsync(dns, endPoint, cancellationToken);
this.dnsCache.Set(key, result.Addresses, result.TimeToLive); 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; return result.Addresses;
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
this.logger.LogInformation($"dns://{dns}无法解析{endPoint.Host}:请求超时"); this.logger.LogWarning($"dns://{dns}无法解析{endPoint.Host}:请求超时");
return Array.Empty<IPAddress>(); return Array.Empty<IPAddress>();
} }
catch (Exception ex) 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>(); return Array.Empty<IPAddress>();
} }
finally finally

View File

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

View File

@ -76,5 +76,10 @@ namespace FastGithub.DomainResolve
{ {
return this.addressElapseds.GetEnumerator(); 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 // appsettings.*.json
"FastGithub": { "FastGithub": {
"HttpProxyPort": 38457, // httplinux/osx使 "HttpProxyPort": 38457, // httplinux/osx使
"FallbackDns": [ // dnscrypt-proxy使 "FallbackDns": [ // dnstcp
"114.114.114.114:53", "114.114.114.114:53",
"119.29.29.29:53" "119.29.29.29:53",
"208.67.222.222:53"
], ],
"DomainConfigs": { "DomainConfigs": {
"*.fastgithub.com": { // *.0 "*.fastgithub.com": { // *.0
@ -28,8 +29,7 @@
"Override": { "Override": {
"Yarp": "Warning", "Yarp": "Warning",
"System": "Warning", "System": "Warning",
"Microsoft": "Warning", "Microsoft": "Warning",
"FastGithub.DomainResolve": "Warning",
"Microsoft.AspNetCore.Server.Kestrel": "Error" "Microsoft.AspNetCore.Server.Kestrel": "Error"
} }
} }