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);
|
||||
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
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using FastGithub.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@ -16,16 +17,19 @@ 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>
|
||||
/// </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>
|
||||
/// 解析ip
|
||||
@ -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;
|
||||
|
||||
@ -76,5 +76,10 @@ namespace FastGithub.DomainResolve
|
||||
{
|
||||
return this.addressElapseds.GetEnumerator();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{string.Join(',', this.addressElapseds.Select(item => item.Adddress))}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,10 @@
|
||||
// 新增的子配置文件appsettings.*.json,重启应用程序才生效
|
||||
"FastGithub": {
|
||||
"HttpProxyPort": 38457, // http代理端口,linux/osx平台使用
|
||||
"FallbackDns": [ // dnscrypt-proxy不可用时使用
|
||||
"FallbackDns": [ // 以下dns必须要支持tcp
|
||||
"114.114.114.114:53",
|
||||
"119.29.29.29:53"
|
||||
"119.29.29.29:53",
|
||||
"208.67.222.222:53"
|
||||
],
|
||||
"DomainConfigs": {
|
||||
"*.fastgithub.com": { // 域名的*表示除.之外0到多个任意字符
|
||||
@ -28,8 +29,7 @@
|
||||
"Override": {
|
||||
"Yarp": "Warning",
|
||||
"System": "Warning",
|
||||
"Microsoft": "Warning",
|
||||
"FastGithub.DomainResolve": "Warning",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore.Server.Kestrel": "Error"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user