Search code examples
c#asp.net-corenloghttp-proxystackify

Stackify not using proxy in ASP.NET Core


In a ASP.Net Core website I am using NLog with a StackifyTarget to log to Stackify Retrace. Our code is running behind a corporate HTTP proxy.

I have some custom code that returns a WebProxy. The WebProxy is then set on StackifyLib.Utils.HttpClient.CustomWebProxy, in the Configure method of the StartUp.cs.

When a log is written, it is written successfully to file, but not to the StackifyTarget.

When I investigate the network traffic using Fiddler, I can see that there are 407/Proxy AuthenticationRequired errors for outbound traffic to the Stackify servers.

Using the same StackifyTarget in a WinForms application, .Net Framework 4.7.2, it just works fine:

<system.net>
    <defaultProxy useDefaultCredentials="true" />
</system.net>

When I set a breakpoint on the Log.Info, I can see that the proxy information is still set on the StackifyLib. How can have StackifyLib work correctly with the proxy, in ASP.Net Core?


Solution

  • The custom code that assigns proxy to CustomWebProxy could also try and assign this first:

    System.Net.WebRequest.DefaultWebProxy = webProxy;
    

    As the very first thing in the application, before Stackify-HttpClient is created.