datalust / serilog-sinks-seq

A Serilog sink that writes events to the Seq structured log server
https://datalust.co/seq
Apache License 2.0
239 stars 50 forks source link

On Azure hosted webapp logs are not getting through Seq, I had to set ServicePointManager.Expect100Continue to false #107

Closed silversens closed 6 years ago

silversens commented 6 years ago

I had to set ServicePointManager.Expect100Continue = false although this isn't good, because it forces the whole app to use this since this is a global setting.

This sink should propose a setting to set ServicePointManager only for seq (https://stackoverflow.com/a/15341369/2047306)

nblumhardt commented 6 years ago

Thanks for the heads-up, @silversens :+1:

It might be possible to work around this by using an HttpClientHandler with the sink, e.g.:

https://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.continuetimeout(v=vs.110).aspx

var handler = new WebRequestHandler();
handler.ContinueTimeout = TimeSpan.Zero;

Log.Logger = new LoggerConfiguration()
    .WriteTo.Seq("http://localhost:5341", messageHandler: handler)
    .CreateLogger();

I can't confirm that this works, but if it does, it might be a quicker workaround than going through the process of adding some kind of direct support here. Are you in a position to spin it up and give it a try?

Best regards, Nick

silversens commented 6 years ago

@nblumhardt thanks for the quick feedback. It implies stop using appsettings and those keys :

  <add key="serilog:using:Seq" value="Serilog.Sinks.Seq" />
  <add key="serilog:write-to:Seq.serverUrl" value="http://localhost:5341" />
  <add key="serilog:write-to:Seq.restrictedToMinimumLevel" value="Verbose" />

So it might work (I still didn't test it) but I'd rather keep having everything in config.

nblumhardt commented 6 years ago

Thanks for the reply 👍

The problem with adding features directly to the sink is that there's a very broad surface area on HttpClient, the handlers for various platforms, and network infrastructure in the middle. Supporting them all specifically would make the maintenance and testing of the sink much harder.

If the workaround works, you could make a slight modification to your config so that it's not picked up by the default ReadFrom.AppSettings():

  <add key="serilogx:write-to:Seq.serverUrl" value="http://localhost:5341" />
  <add key="serilogx:write-to:Seq.restrictedToMinimumLevel" value="Verbose" />
  <add key="serilogx:write-to:Seq.expect100Continue" value="False" />

and then in code use:

.WriteTo.Seq(ConfigurationManager.AppSettings["serilogx:write-to:Seq.serverUrl"] /* etc */)

What do you think?

silversens commented 6 years ago

Thanks for the reply. This is a solution I'll consider.

Although, even if you're right "exposing every configurable thing in settings is not a solution", I still believe Azure won't be a rare platform. We'll see if supports for this gets requested a lot with time.

Regards, Sÿl

nblumhardt commented 6 years ago

Thanks, yes, this makes sense 👍

A lot of Seq customers currently use Seq successfully with Azure - I wonder if it's possibly something to do with your virtual network configuration? I haven't personally published an Azure web app for quite a while, though, so given an opportunity I'll spin one up and see if I hit the same problem. Thanks for the feedback!

Nick

silversens commented 6 years ago

Nick,

Just to be clear, I meant Azure in PaaS, so no virtual network configuration. You can try with free hosting.

Sÿl

nblumhardt commented 6 years ago

Hoping that the configuration-in-code approach is working well for you. I haven't seen any further reports of this, so closing, but keen for anyone else who hits it to chime in here :-) Cheers!