Logging error responses - AquaticInformatics/aquarius-sdk-net GitHub Wiki

The AQUARIUS SDK is based on the ServiceStack.Client package, which uses the ServiceStack configurable logging interface to log any 4xx-5xx HTTP status response received, to a wide variety of common .NET logging providers (log4net, NLog, Elmah, Slack, and others).

See the Registration Examples for details.

All your integration needs to do is register your logging provider once at startup, as early as possible. Typically this registration occurs within in the Program.cs or Global.asax.cs file.

Configuration within Program.cs for console apps

static void Main(string[] args)
{
    // Register the concrete logging provider
    LogManager.LogFactory = new Log4NetFactory();

    // On to the main program
    ...
}

Configuration within Global.asax.cs for ASP.NET apps

public class Global : HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        // Register the concrete logging provider
        LogManager.LogFactory = new NLogFactory();
        
        // Start your app
        ...
    }
}

What is logged when a request fails

When a HTTP request fails with a 4xx or 5xx status code, the ServiceStack.Client code will convert the response into a WebServiceException object and perform the following logic:

private static readonly ILog log = LogManager.GetLogger(typeof(ServiceClientBase));  // For synchronous requests
private static readonly ILog Log = LogManager.GetLogger(typeof(AsyncServiceClient)); // For asynchronous requests
...

log.Error(webServiceException);

if (log.IsDebugEnabled)
{
    log.Debug($"Status Code : {webServiceException.StatusCode}");
    log.Debug($"Status Description: {webServiceException.StatusDescription}");
}

throw webServiceException;

You can configure the verbosity of the ServiceClientBase or AyncServiceClient logger in your application to control the output of any captured errors.