question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Audit info parameters - WebAPI

See original GitHub issue

Hi, I have custom WebAPI on the remote server. On every request there is a warning in the log file.

WARN|Abp.Auditing.WebAuditInfoProvider|System.Net.Sockets.SocketException (0x80004005): No such host is known at System.Net.Dns.GetAddrInfo(String name) at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6) at System.Net.Dns.GetHostAddresses(String hostNameOrAddress) at Abp.Auditing.WebAuditInfoProvider.GetClientIpAddress(HttpContext httpContext) at Abp.Auditing.WebAuditInfoProvider.Fill(AuditInfo auditInfo)

What’s the problem?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, May 6, 2016

I cached exceptions for Dns.GetHostAddresses call. New code is like that:

protected virtual string GetClientIpAddress(HttpContext httpContext)
{
    var clientIp = httpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ??
                    httpContext.Request.ServerVariables["REMOTE_ADDR"];

    try
    {
        foreach (var hostAddress in Dns.GetHostAddresses(clientIp))
        {
            if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                return hostAddress.ToString();
            }
        }

        foreach (var hostAddress in Dns.GetHostAddresses(Dns.GetHostName()))
        {
            if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                return hostAddress.ToString();
            }
        }
    }
    catch (Exception ex)
    {
        Logger.Debug(ex.ToString());
    }

    return clientIp;
}

As you see, I did it virtual. So, you can create a new class inherits from WebAuditInfoProvider and override GetClientIpAddress to change code for your application. Then you can replace IAuditInfoProvider service with your own implementation (https://github.com/aspnetboilerplate/aspnetboilerplate/issues/983#issuecomment-217428154).

0reactions
automyscommented, May 19, 2016

Thanks @tamys, this works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Audit.WebApi
Generate Audit Trails for ASP.NET MVC Web API calls. This library provides a configurable infrastructure to log interactions with your Asp.NET (or Asp.NET...
Read more >
c# - Web API audit logging
It can record action method calls with caller info, arguments, output, duration, exceptions and more. Take a look at Audit.WebApi.
Read more >
How to Audit Your ASP.NET Core WebApi
Firstly, the data gets stored needs to be defined. Different people (because of their roles) can expect different details from an audit log. ......
Read more >
How to Audit Your ASP.NET Core WebApi
Add/Remove audit properties​​ Every log is captured in an AuditScope. AuditScope contains some general info about the event as well as the action ......
Read more >
Audit Logs Integration Guide - Airtable Web API
The audit log events API is accessible via PAT and OAuth. ... This can be configured using the pageSize parameter and is limited...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found