datalust/serilog-sinks-seq

Not writing to Seq with Net461 and Configuration installed

Closed this issue · 6 comments

This goes in the thoroughly weird bucket and not really expecting any possible fix, but wanted to at least let other people know. If anything, this may be an issue with the Microsoft Configurations package.
If all of the following are true;

  • You are using the new csproj format in VS2017
  • You are targeting net461
  • You also install Microsoft.Extensions.Configurations

then the seq sink will silently fail to write to Seq. All the other bits of serilog works fine, just nothing gets sent to Seq.
This may be related to #56, though adding <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> doesn't seem to help.

Given this console app:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        var logConfig = new LoggerConfiguration().WriteTo.Seq("https://myserver", apiKey: "XXX");
        Log.Logger = logConfig.CreateLogger();
        Log.Information("TEST");
        Log.CloseAndFlush();
    }
}

This .csproj does not work

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.1" />
    <PackageReference Include="Serilog.Sinks.Seq" Version="3.2.0" />
  </ItemGroup>

</Project>

This .csproj works:

(removed Microsoft.Extensions.Configuration)

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Serilog.Sinks.Seq" Version="3.2.0" />
  </ItemGroup>

</Project>

This .csproj works:

(Targeting Net 4.5.1 instead of 4.6.1)

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net451</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.1" />
    <PackageReference Include="Serilog.Sinks.Seq" Version="3.2.0" />
  </ItemGroup>

</Project>

Thank you for the report Franz.

It looks like we've hit this bug: https://github.com/dotnet/corefx/issues/15031

This CSPROJ works (note the explicit System.Net.Http package dependency):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>   
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="microsoft.extensions.configuration" Version="1.1.1" />
    <PackageReference Include="serilog.sinks.seq" Version="3.2.0" />
    <PackageReference Include="system.net.http" Version="4.3.1" />
  </ItemGroup>

</Project>

I'm wondering whether we can get around this, without changing dependency versions in the existing targets, by adding an explicit net46 TFM to our project.json, and adding the explicit dependency there?

@nblumhardt Thanks for getting back. Interesting thought; I'll try to spike it.

FWIW, I tried adding a net4.6 target to Serilog.Sinks.Seq, generated the package and used that - but it doesn't seem to resolve it. I've tried a few different approaches, but I keep ending up with System.Net.Http 4.1.1 instead of 4.3.1 and then failing on DiagnosticSource as in #56 - and <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> doesn't resolve that in my test setup.
I think this is beyond me to understand, sorry.
As it is, not a biggie and probably not much that can be done at Serilog level...

@flytzen I've had some succeess finding a way around this (I hope) - https://www.nuget.org/packages/Serilog.Sinks.Seq/3.3.0-dev-00110 should cover it, it'd be interesting to hear whether it works in your project. Cheers!

Yep, that seems to have fixed it.
Interestingly, I tried the same thing you did with adding a specific NET46 TFM but couldn't get it to work. However, I didn't touch the dependencies for netstandard1.x, so wonder if maybe that made a difference. Or maybe I just messed up my tests :)

Thanks for resolving this!