Search code examples
c#app-configserilog

Cannot specify Http sink for serilog in appsettings with Serilog.Sinks.Http nuget package


I had a serilog configuration in code like this:

            _seriLog = new LoggerConfiguration()
                .WriteTo.DurableHttpUsingTimeRolledBuffers("http://192.168.100.178:8080")
                .CreateLogger();

and wanted to change it to a config file. I added the Seriolog.Settings.AppSettings nuget package, and tried to follow the directions on github.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="serilog:minimum-level"  value="Verbose"/>
        <add key="serilog:using:Http" value="Serilog.Sinks.Http" />
        <add key="serilog:write-to:Http.requestUri" value="http://192.168.100.178:8080" />
    </appSettings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
</configuration>

When I start the app, it hangs. There is no exception thrown, and the stack trace does not make sense to me. Here is the stack-trace for the LogManager thread: stack trace

Update: There was actually a exception thrown from the startup project: Could not load file or assembly 'Serilog.Sinks.Http'. See solution below.


Solution

  • There WAS in fact an exception getting thrown. I did not see this because my exception settings were changed accidentally. ProjectA complained that it could not find Serilog.Sinks.Http. ProjectA is a .net Framework project, and it was referencing ProjectB which is .net Standard. My logger implementation and Serilog packages are both inside ProjectB, which is why ProjectA depends on it. I found this github issue, and added Serilog.Sink.Http nuget package to ProjectA. Fixed the problem instantly.