dns日志
This commit is contained in:
parent
5f2a1f4804
commit
7d7b67948b
@ -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
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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))}]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,10 @@
|
|||||||
// 新增的子配置文件appsettings.*.json,重启应用程序才生效
|
// 新增的子配置文件appsettings.*.json,重启应用程序才生效
|
||||||
"FastGithub": {
|
"FastGithub": {
|
||||||
"HttpProxyPort": 38457, // http代理端口,linux/osx平台使用
|
"HttpProxyPort": 38457, // http代理端口,linux/osx平台使用
|
||||||
"FallbackDns": [ // dnscrypt-proxy不可用时使用
|
"FallbackDns": [ // 以下dns必须要支持tcp
|
||||||
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user