C
C#7mo ago
user

func wont print the logging level before the exception

private static IPAddress GetIpAddressFromDomain(string domain)
{
IPAddress[] addresses = Dns.GetHostAddresses(domain);
foreach (IPAddress address in addresses)
{
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return address;
}
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[" + currentTimeforlogs.ToString("HH:mm:ss") + " ERROR]");
Console.ResetColor();
throw new Exception($"Failed to resolve IP address for domain: {domain}");
}
}
private static IPAddress GetIpAddressFromDomain(string domain)
{
IPAddress[] addresses = Dns.GetHostAddresses(domain);
foreach (IPAddress address in addresses)
{
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return address;
}
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[" + currentTimeforlogs.ToString("HH:mm:ss") + " ERROR]");
Console.ResetColor();
throw new Exception($"Failed to resolve IP address for domain: {domain}");
}
}
it just wont print the [{time} ERROR] then the exception, it just prints the exception, also i need help with getting IPs from domain names, ill send the src if i have to.
2 Replies
Saiyanslayer
Saiyanslayer7mo ago
where is currentTimeforlogs coming from? I'd start by placing a breakpoint on that line and checking what each variable's value is and it seems like you'd throw an error everytime that method is ran. You don't excape before throwing the exception
canton7
canton77mo ago
Console.Write doesn't do a flush -- a flush is normally done by writing a new line, but if you need to you can manually flush But, trying to write an error message by throwing an exception is... odd
Want results from more Discord servers?
Add your server